]> granicus.if.org Git - clang/commitdiff
Fix processing of -Ufoo to not inject "#undef foo 1" into the predefines
authorChris Lattner <sabre@nondot.org>
Fri, 15 May 2009 16:08:43 +0000 (16:08 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 15 May 2009 16:08:43 +0000 (16:08 +0000)
buffer.  This caused exciting nonsense like this:

$ clang t.c -fsyntax-only -UMACRO
In file included from <built-in>:104:
<command line>:1:14: warning: extra tokens at end of #undef directive [-Wextra-tokens]
#undef MACRO 1
             ^
             //
1 diagnostic generated.

rdar://6891800

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71860 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/InitPreprocessor.cpp

index f9929d1558a6f5c095695ef6cd12c8dc9b3514a7..102f385f7e054c7da386b2befc8b639f8b5f7ff3 100644 (file)
@@ -51,6 +51,16 @@ static void DefineBuiltinMacro(std::vector<char> &Buf, const char *Macro,
   Buf.push_back('\n');
 }
 
+// Append a #undef line to Buf for Macro.  Macro should be of the form XXX
+// and we emit "#undef XXX".
+static void UndefineBuiltinMacro(std::vector<char> &Buf, const char *Macro) {
+  // Push "macroname".
+  const char *Command = "#undef ";
+  Buf.insert(Buf.end(), Command, Command+strlen(Command));
+  Buf.insert(Buf.end(), Macro, Macro+strlen(Macro));
+  Buf.push_back('\n');
+}
+
 /// Add the quoted name of an implicit include file.
 static void AddQuotedIncludePath(std::vector<char> &Buf, 
                                  const std::string &File) {
@@ -441,7 +451,7 @@ bool InitializePreprocessor(Preprocessor &PP,
   for (PreprocessorInitOptions::macro_iterator I = InitOpts.macro_begin(),
        E = InitOpts.macro_end(); I != E; ++I) {
     if (I->second)  // isUndef
-      DefineBuiltinMacro(PredefineBuffer, I->first.c_str(), "#undef ");
+      UndefineBuiltinMacro(PredefineBuffer, I->first.c_str());
     else
       DefineBuiltinMacro(PredefineBuffer, I->first.c_str());
   }