[cfe-commits] r71860 - /cfe/trunk/lib/Frontend/InitPreprocessor.cpp

Chris Lattner sabre at nondot.org
Fri May 15 09:09:06 PDT 2009


Author: lattner
Date: Fri May 15 11:08:43 2009
New Revision: 71860

URL: http://llvm.org/viewvc/llvm-project?rev=71860&view=rev
Log:
Fix processing of -Ufoo to not inject "#undef foo 1" into the predefines
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

Modified:
    cfe/trunk/lib/Frontend/InitPreprocessor.cpp

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=71860&r1=71859&r2=71860&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Fri May 15 11:08:43 2009
@@ -51,6 +51,16 @@
   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 @@
   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());
   }





More information about the cfe-commits mailing list