diff options
author | Chris Lattner <sabre@nondot.org> | 2007-09-24 05:14:57 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-09-24 05:14:57 +0000 |
commit | d05e44e74e20301c71ade9f0ccfd52e738b794bb (patch) | |
tree | c3dae477ad6e1cb2cb416b6c357b4037e64de0e0 | |
parent | 7d98b23f1ad24c34dcbd8767394bfccf1f01ee43 (diff) | |
download | bcm5719-llvm-d05e44e74e20301c71ade9f0ccfd52e738b794bb.tar.gz bcm5719-llvm-d05e44e74e20301c71ade9f0ccfd52e738b794bb.zip |
If we see an invalid #ifdef directive, enter a conditional compilation region
so that we don't emit an error on the #endif. Suggestion by Neil.
llvm-svn: 42258
-rw-r--r-- | clang/Lex/Preprocessor.cpp | 7 | ||||
-rw-r--r-- | clang/test/Preprocessor/ifdef-recover.c | 7 |
2 files changed, 13 insertions, 1 deletions
diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp index b51222cefd3..f43eae1c982 100644 --- a/clang/Lex/Preprocessor.cpp +++ b/clang/Lex/Preprocessor.cpp @@ -2121,8 +2121,13 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef, ReadMacroName(MacroNameTok); // Error reading macro name? If so, diagnostic already issued. - if (MacroNameTok.getKind() == tok::eom) + if (MacroNameTok.getKind() == tok::eom) { + // Skip code until we get to #endif. This helps with recovery by not + // emitting an error when the #endif is reached. + SkipExcludedConditionalBlock(DirectiveTok.getLocation(), + /*Foundnonskip*/false, /*FoundElse*/false); return; + } // Check to see if this is the last token on the #if[n]def line. CheckEndOfDirective(isIfndef ? "#ifndef" : "#ifdef"); diff --git a/clang/test/Preprocessor/ifdef-recover.c b/clang/test/Preprocessor/ifdef-recover.c new file mode 100644 index 00000000000..2009514f5e1 --- /dev/null +++ b/clang/test/Preprocessor/ifdef-recover.c @@ -0,0 +1,7 @@ +/* RUN: clang %s 2>&1 | grep error: | count 1 + */ + +#ifdef + +#endif + |