[llvm-branch-commits] [cfe-branch] r71868 - /cfe/branches/Apple/Dib/lib/Frontend/InitPreprocessor.cpp

Mike Stump mrs at apple.com
Fri May 15 09:21:53 PDT 2009


Author: mrs
Date: Fri May 15 11:21:50 2009
New Revision: 71868

URL: http://llvm.org/viewvc/llvm-project?rev=71868&view=rev
Log:
Merge in 71860:

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/branches/Apple/Dib/lib/Frontend/InitPreprocessor.cpp

Modified: cfe/branches/Apple/Dib/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Frontend/InitPreprocessor.cpp?rev=71868&r1=71867&r2=71868&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Frontend/InitPreprocessor.cpp Fri May 15 11:21:50 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 llvm-branch-commits mailing list