unsigned Optimize : 1; // Whether __OPTIMIZE__ should be defined.
unsigned OptimizeSize : 1; // Whether __OPTIMIZE_SIZE__ should be
// defined.
+ unsigned PICLevel : 2; // The value for __PIC__, if non-zero.
+
private:
unsigned GC : 2; // Objective-C Garbage Collection modes. We declare
// this enum as unsigned because MSVC insists on making enums
Optimize = 0;
OptimizeSize = 0;
+
+ PICLevel = 0;
}
GCMode getGCMode() const { return (GCMode) GC; }
CmdArgs.push_back("--relocation-model");
CmdArgs.push_back(Model);
+ // Infer the __PIC__ value.
+ //
+ // FIXME: This isn't quite right on Darwin, which always sets
+ // __PIC__=2.
+ if (strcmp(Model, "pic") == 0 || strcmp(Model, "dynamic-no-pic") == 0) {
+ if (Args.hasArg(options::OPT_fPIC))
+ CmdArgs.push_back("-pic-level=2");
+ else
+ CmdArgs.push_back("-pic-level=1");
+ }
+
if (Args.hasArg(options::OPT_ftime_report))
CmdArgs.push_back("--time-passes");
// FIXME: Set --enable-unsafe-fp-math.
if (PP.getLangOptions().ObjC1) {
DefineBuiltinMacro(Buf, "__OBJC__=1");
- if (PP.getLangOptions().ObjCNonFragileABI)
+ if (PP.getLangOptions().ObjCNonFragileABI) {
DefineBuiltinMacro(Buf, "__OBJC2__=1");
+ DefineBuiltinMacro(Buf, "OBJC_ZEROCOST_EXCEPTIONS=1");
+ }
if (PP.getLangOptions().getGCMode() != LangOptions::NonGC)
DefineBuiltinMacro(Buf, "__OBJC_GC__=1");
DefineBuiltinMacro(Buf, "__DYNAMIC__=1");
DefineBuiltinMacro(Buf, "__FINITE_MATH_ONLY__=0");
DefineBuiltinMacro(Buf, "__NO_INLINE__=1");
- DefineBuiltinMacro(Buf, "__PIC__=1");
+
+ if (unsigned PICLevel = PP.getLangOptions().PICLevel) {
+ sprintf(MacroBuf, "__PIC__=%d", PICLevel);
+ DefineBuiltinMacro(Buf, MacroBuf);
+
+ sprintf(MacroBuf, "__pic__=%d", PICLevel);
+ DefineBuiltinMacro(Buf, MacroBuf);
+ }
// Macros to control C99 numerics and <float.h>
DefineBuiltinMacro(Buf, "__FLT_EVAL_METHOD__=0");
--- /dev/null
+// RUN: clang -static -dM -E -o %t %s &&
+// RUN: grep '#define __PIC__' %t | count 0 &&
+// RUN: grep '#define __pic__' %t | count 0 &&
+// RUN: clang -fpic -dM -E -o %t %s &&
+// RUN: grep '#define __PIC__ 1' %t | count 1 &&
+// RUN: grep '#define __pic__ 1' %t | count 1 &&
+// RUN: clang -fPIC -dM -E -o %t %s &&
+// RUN: grep '#define __PIC__ 2' %t | count 1 &&
+// RUN: grep '#define __pic__ 2' %t | count 1 &&
+// RUN: true
llvm::cl::desc("Optimization level"),
llvm::cl::init(0));
+static llvm::cl::opt<unsigned>
+PICLevel("pic-level", llvm::cl::Prefix,
+ llvm::cl::desc("Value for __PIC__"),
+ llvm::cl::init(0));
+
// FIXME: add:
// -fdollars-in-identifiers
static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
// -Os implies -O2
if (Options.OptimizeSize || OptLevel)
Options.Optimize = 1;
+
+ assert(PICLevel <= 2 && "Invalid value for -pic-level");
+ Options.PICLevel = PICLevel;
}
static llvm::cl::opt<bool>