This patch makes clang predefine some macros even when asked not to by the
-undef flag. I found real-world code which passes -undef and then tests for
these macros.

$ gcc -undef -dM -E -
#define __STDC_HOSTED__ 1
#define __STDC__ 1
$ gcc -undef -dM -E -x assembler-with-cpp -
#define __ASSEMBLER__ 1
#define __STDC_HOSTED__ 1
#define __STDC__ 1
$ gcc-4.6 -undef -dM -E -x assembler-with-cpp - -ffreestanding
#define __ASSEMBLER__ 1
#define __STDC_HOSTED__ 0
#define __STDC__ 1

Please review!

Nick
Index: lib/Frontend/InitPreprocessor.cpp
===================================================================
--- lib/Frontend/InitPreprocessor.cpp	(revision 132624)
+++ lib/Frontend/InitPreprocessor.cpp	(working copy)
@@ -256,13 +256,6 @@
 
   // Initialize language-specific preprocessor defines.
 
-  // These should all be defined in the preprocessor according to the
-  // current language configuration.
-  if (!LangOpts.Microsoft && !LangOpts.TraditionalCPP)
-    Builder.defineMacro("__STDC__");
-  if (LangOpts.AsmPreprocessor)
-    Builder.defineMacro("__ASSEMBLER__");
-
   if (!LangOpts.CPlusPlus) {
     if (LangOpts.C99)
       Builder.defineMacro("__STDC_VERSION__", "199901L");
@@ -277,11 +270,6 @@
   if (LangOpts.CPlusPlus0x)
     Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");
 
-  if (LangOpts.Freestanding)
-    Builder.defineMacro("__STDC_HOSTED__", "0");
-  else
-    Builder.defineMacro("__STDC_HOSTED__");
-
   if (LangOpts.ObjC1) {
     Builder.defineMacro("__OBJC__");
     if (LangOpts.ObjCNonFragileABI) {
@@ -572,6 +560,19 @@
     InitializePredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(),
                                FEOpts, Builder);
 
+  // Even with predefines off, some macros are still predefined.
+  // These should all be defined in the preprocessor according to the
+  // current language configuration.
+  if (!PP.getLangOptions().Microsoft && !PP.getLangOptions().TraditionalCPP)
+    Builder.defineMacro("__STDC__");
+  if (PP.getLangOptions().AsmPreprocessor)
+    Builder.defineMacro("__ASSEMBLER__");
+  if (PP.getLangOptions().Freestanding)
+    Builder.defineMacro("__STDC_HOSTED__", "0");
+  else
+    Builder.defineMacro("__STDC_HOSTED__");
+
+
   // Add on the predefines from the driver.  Wrap in a #line directive to report
   // that they come from the command line.
   if (!PP.getLangOptions().AsmPreprocessor)
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to