[cfe-commits] r68621 - in /cfe/trunk: include/clang/Basic/LangOptions.h lib/Driver/Tools.cpp lib/Lex/Preprocessor.cpp test/Preprocessor/optimize.c tools/clang-cc/clang-cc.cpp utils/builtin-defines.c

Daniel Dunbar daniel at zuster.org
Wed Apr 8 11:03:55 PDT 2009


Author: ddunbar
Date: Wed Apr  8 13:03:55 2009
New Revision: 68621

URL: http://llvm.org/viewvc/llvm-project?rev=68621&view=rev
Log:
More fixes to builtin preprocessor defines.
 - Add -static-define option driver can use when __STATIC__ should be
   defined (instead of __DYNAMIC__).

 - Don't set __OPTIMIZE_SIZE__ on Os, __OPTIMIZE_SIZE__ is tied to Oz.

 - Set __NO_INLINE__ following GCC 4.2.

 - Set __GNU_GNU_INLINE__ or __GNU_STDC_INLINE__ following GCC 4.2.

 - Set __EXCEPTIONS for Objective-C NonFragile ABI.

 - Set __STRICT_ANSI__ for standard conforming modes.

 - I added a clang style test case in utils for this, but its not
   particularly portable and I don't think it belongs in the test
   suite.

Added:
    cfe/trunk/utils/builtin-defines.c
Modified:
    cfe/trunk/include/clang/Basic/LangOptions.h
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/test/Preprocessor/optimize.c
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=68621&r1=68620&r2=68621&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Wed Apr  8 13:03:55 2009
@@ -68,8 +68,14 @@
   unsigned Optimize          : 1; // Whether __OPTIMIZE__ should be defined.
   unsigned OptimizeSize      : 1; // Whether __OPTIMIZE_SIZE__ should be 
                                   // defined.
+  unsigned Static            : 1; // Should __STATIC__ be defined (as
+                                  // opposed to __DYNAMIC__).
   unsigned PICLevel          : 2; // The value for __PIC__, if non-zero.
 
+  unsigned GNUInline         : 1; // Should GNU inline semantics be
+                                  // used (instead of C99 semantics).
+  unsigned NoInline          : 1; // Should __NO_INLINE__ be defined.
+
 private:
   unsigned GC : 2; // Objective-C Garbage Collection modes.  We declare
                    // this enum as unsigned because MSVC insists on making enums
@@ -114,8 +120,12 @@
     Optimize = 0;
     OptimizeSize = 0;
 
+    Static = 0;
     PICLevel = 0;
 
+    GNUInline = 0;
+    NoInline = 0;
+
     MainFileName = 0;
   }
   

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=68621&r1=68620&r2=68621&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Apr  8 13:03:55 2009
@@ -79,6 +79,11 @@
   CmdArgs.push_back("-main-file-name");
   CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs));
 
+  // Some flags which affect the language (via preprocessor
+  // defines). See darwin::CC1::AddCPPArgs.
+  if (Args.hasArg(options::OPT_static))
+    CmdArgs.push_back("-static-define");
+
   if (isa<AnalyzeJobAction>(JA)) {
     // Add default argument set.
     //

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=68621&r1=68620&r2=68621&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Wed Apr  8 13:03:55 2009
@@ -486,6 +486,10 @@
     DefineBuiltinMacro(Buf, "__STDC_VERSION__=199901L");
   else if (0) // STDC94 ?
     DefineBuiltinMacro(Buf, "__STDC_VERSION__=199409L");
+
+  // Standard conforming mode?
+  if (!PP.getLangOptions().GNUMode)
+    DefineBuiltinMacro(Buf, "__STRICT_ANSI__=1");
   
   if (PP.getLangOptions().CPlusPlus0x)
     DefineBuiltinMacro(Buf, "__GXX_EXPERIMENTAL_CXX0X__");
@@ -500,6 +504,7 @@
     if (PP.getLangOptions().ObjCNonFragileABI) {
       DefineBuiltinMacro(Buf, "__OBJC2__=1");
       DefineBuiltinMacro(Buf, "OBJC_ZEROCOST_EXCEPTIONS=1");
+      DefineBuiltinMacro(Buf, "__EXCEPTIONS=1");
     }
 
     if (PP.getLangOptions().getGCMode() != LangOptions::NonGC)
@@ -628,9 +633,20 @@
   
   // Build configuration options.  FIXME: these should be controlled by
   // command line options or something.
-  DefineBuiltinMacro(Buf, "__DYNAMIC__=1");
   DefineBuiltinMacro(Buf, "__FINITE_MATH_ONLY__=0");
-  DefineBuiltinMacro(Buf, "__NO_INLINE__=1");
+
+  if (PP.getLangOptions().Static)
+    DefineBuiltinMacro(Buf, "__STATIC__=1");
+  else
+    DefineBuiltinMacro(Buf, "__DYNAMIC__=1");
+
+  if (PP.getLangOptions().GNUInline)
+    DefineBuiltinMacro(Buf, "__GNUC_GNU_INLINE__=1");
+  else
+    DefineBuiltinMacro(Buf, "__GNUC_STDC_INLINE__=1");
+
+  if (PP.getLangOptions().NoInline)
+    DefineBuiltinMacro(Buf, "__NO_INLINE__=1");
 
   if (unsigned PICLevel = PP.getLangOptions().PICLevel) {
     sprintf(MacroBuf, "__PIC__=%d", PICLevel);

Modified: cfe/trunk/test/Preprocessor/optimize.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/optimize.c?rev=68621&r1=68620&r2=68621&view=diff

==============================================================================
--- cfe/trunk/test/Preprocessor/optimize.c (original)
+++ cfe/trunk/test/Preprocessor/optimize.c Wed Apr  8 13:03:55 2009
@@ -23,7 +23,7 @@
   #ifndef __OPTIMIZE__
     #error "__OPTIMIZE__ not defined"
   #endif
-  #ifndef __OPTIMIZE_SIZE__
+  #ifdef __OPTIMIZE_SIZE__
     #error "__OPTIMIZE_SIZE__ not defined"
   #endif
 #endif

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=68621&r1=68620&r2=68621&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Apr  8 13:03:55 2009
@@ -624,9 +624,10 @@
          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));
+PICLevel("pic-level", llvm::cl::desc("Value for __PIC__"));
+
+static llvm::cl::opt<bool>
+StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
 
 // FIXME: add:
 //   -fdollars-in-identifiers
@@ -771,16 +772,23 @@
   if (EmitAllDecls)
     Options.EmitAllDecls = 1;
 
-  if (OptSize)
-    Options.OptimizeSize = 1;
+  // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't
+  // support.
+  Options.OptimizeSize = 0;
   
   // -Os implies -O2
-  if (Options.OptimizeSize || OptLevel)
+  if (OptSize || OptLevel)
     Options.Optimize = 1;
 
   assert(PICLevel <= 2 && "Invalid value for -pic-level");
   Options.PICLevel = PICLevel;
 
+  Options.GNUInline = !Options.C99;
+  // FIXME: This is affected by other options (-fno-inline). 
+  Options.NoInline = !OptSize && !OptLevel;
+
+  Options.Static = StaticDefine;
+
   if (MainFileName.getPosition())
     Options.setMainFileName(MainFileName.c_str());
 }

Added: cfe/trunk/utils/builtin-defines.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/builtin-defines.c?rev=68621&view=auto

==============================================================================
--- cfe/trunk/utils/builtin-defines.c (added)
+++ cfe/trunk/utils/builtin-defines.c Wed Apr  8 13:03:55 2009
@@ -0,0 +1,79 @@
+/* 
+This is a clang style test case for checking that preprocessor
+defines match gcc.
+*/
+
+/*
+RUN: for arch in -m32 -m64; do \
+RUN:   for lang in -std=gnu89 -ansi -std=c99 -std=gnu99; do \
+RUN:     for input in c objective-c; do \
+RUN:       for opts in "-O0" "-O1 -dynamic" "-O2 -static" "-Os"; do     \
+RUN:         echo "-- $arch, $lang, $input, $opts --"; \
+RUN:         for cc in 0 1; do \
+RUN:           if [ "$cc" == 0 ]; then \
+RUN:             cc_prog=clang; \
+RUN:             output=%t0; \
+RUN:           else \
+RUN:             cc_prog=gcc; \
+RUN:             output=%t1; \
+RUN:           fi; \
+RUN:           $cc_prog $arch $lang $opts -dM -E -x $input %s | sort > $output; \
+RUN:          done; \
+RUN:          if (! diff %t0 %t1); then exit 1; fi; \
+RUN:       done; \
+RUN:     done; \
+RUN:   done; \
+RUN: done;
+*/
+
+/* We don't care about this difference */
+#ifdef __PIC__
+#if __PIC__ == 1
+#undef __PIC__
+#undef __pic__
+#define __PIC__ 2
+#define __pic__ 2
+#endif
+#endif
+
+/* Undefine things we don't expect to match. */
+#undef __DEC_EVAL_METHOD__
+#undef __INT16_TYPE__
+#undef __INT32_TYPE__
+#undef __INT64_TYPE__
+#undef __INT8_TYPE__
+#undef __SSP__
+#undef __APPLE_CC__
+#undef __VERSION__
+#undef __clang__
+#undef __llvm__
+#undef __nocona
+#undef __nocona__
+#undef __k8
+#undef __k8__
+#undef __tune_nocona__
+#undef __tune_core2__
+#undef __POINTER_WIDTH__
+#undef __INTPTR_TYPE__
+
+#undef __DEC128_DEN__
+#undef __DEC128_EPSILON__
+#undef __DEC128_MANT_DIG__
+#undef __DEC128_MAX_EXP__
+#undef __DEC128_MAX__
+#undef __DEC128_MIN_EXP__
+#undef __DEC128_MIN__
+#undef __DEC32_DEN__
+#undef __DEC32_EPSILON__
+#undef __DEC32_MANT_DIG__
+#undef __DEC32_MAX_EXP__
+#undef __DEC32_MAX__
+#undef __DEC32_MIN_EXP__
+#undef __DEC32_MIN__
+#undef __DEC64_DEN__
+#undef __DEC64_EPSILON__
+#undef __DEC64_MANT_DIG__
+#undef __DEC64_MAX_EXP__
+#undef __DEC64_MAX__
+#undef __DEC64_MIN_EXP__
+#undef __DEC64_MIN__





More information about the cfe-commits mailing list