diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2011-06-07 06:07:12 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2011-06-07 06:07:12 +0000 |
commit | a9c6441c73686c34fdf5de681bfd81381fd0903c (patch) | |
tree | eadd993fd08b199bacdfb6ec42f7ac55879f1391 | |
parent | 5b01b8319012c6b568de6dfff935c1b16184952f (diff) |
The macros defined by the language standard are still available even when the
-undef flag is passed in. Also __ASSEMBLER__ with -x assembler-with-cpp. (Don't
ask.)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132708 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Frontend/InitPreprocessor.cpp | 63 | ||||
-rw-r--r-- | test/Frontend/undef.c | 4 |
2 files changed, 41 insertions, 26 deletions
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index e63036a421..26230d6a57 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -221,6 +221,37 @@ static void DefineExactWidthIntType(TargetInfo::IntType Ty, ConstSuffix); } +static void InitializeStandardPredefinedMacros(const TargetInfo &TI, + const LangOptions &LangOpts, + const FrontendOptions &FEOpts, + MacroBuilder &Builder) { + if (!LangOpts.Microsoft && !LangOpts.TraditionalCPP) + Builder.defineMacro("__STDC__"); + if (LangOpts.Freestanding) + Builder.defineMacro("__STDC_HOSTED__", "0"); + else + Builder.defineMacro("__STDC_HOSTED__"); + + if (!LangOpts.CPlusPlus) { + if (LangOpts.C99) + Builder.defineMacro("__STDC_VERSION__", "199901L"); + else if (!LangOpts.GNUMode && LangOpts.Digraphs) + Builder.defineMacro("__STDC_VERSION__", "199409L"); + } else { + if (LangOpts.GNUMode) + Builder.defineMacro("__cplusplus"); + else + // C++ [cpp.predefined]p1: + // The name_ _cplusplus is defined to the value 199711L when compiling a + // C++ translation unit. + Builder.defineMacro("__cplusplus", "199711L"); + } + + // Not "standard" per se, but available even with the -undef flag. + if (LangOpts.AsmPreprocessor) + Builder.defineMacro("__ASSEMBLER__"); +} + static void InitializePredefinedMacros(const TargetInfo &TI, const LangOptions &LangOpts, const FrontendOptions &FEOpts, @@ -256,20 +287,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI, // 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"); - else if (!LangOpts.GNUMode && LangOpts.Digraphs) - Builder.defineMacro("__STDC_VERSION__", "199409L"); - } - // Standard conforming mode? if (!LangOpts.GNUMode) Builder.defineMacro("__STRICT_ANSI__"); @@ -277,11 +294,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI, 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) { @@ -324,13 +336,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI, if (LangOpts.CPlusPlus) { Builder.defineMacro("__GNUG__", "4"); Builder.defineMacro("__GXX_WEAK__"); - if (LangOpts.GNUMode) - Builder.defineMacro("__cplusplus"); - else - // C++ [cpp.predefined]p1: - // The name_ _cplusplusis defined to the value 199711L when compiling a - // C++ translation unit. - Builder.defineMacro("__cplusplus", "199711L"); Builder.defineMacro("__private_extern__", "extern"); } @@ -572,6 +577,12 @@ void clang::InitializePreprocessor(Preprocessor &PP, 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. + InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(), + FEOpts, Builder); + // 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) diff --git a/test/Frontend/undef.c b/test/Frontend/undef.c new file mode 100644 index 0000000000..f539cdce11 --- /dev/null +++ b/test/Frontend/undef.c @@ -0,0 +1,4 @@ +// RUN: %clang -undef -x assembler-with-cpp -E %s +#ifndef __ASSEMBLER__ +#error "Must be preprocessed as assembler." +#endif |