diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-05-15 16:08:43 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-05-15 16:08:43 +0000 |
| commit | 4579b76ff60fcb99c2699f7a9026a4fd18e460be (patch) | |
| tree | 829acc59e01b4eacd6082c74e6e71c159e1f13be | |
| parent | 3281977dbbc20c78f200e2810af75be2674132a0 (diff) | |
| download | bcm5719-llvm-4579b76ff60fcb99c2699f7a9026a4fd18e460be.tar.gz bcm5719-llvm-4579b76ff60fcb99c2699f7a9026a4fd18e460be.zip | |
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
llvm-svn: 71860
| -rw-r--r-- | clang/lib/Frontend/InitPreprocessor.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index f9929d1558a..102f385f7e0 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -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()); } |

