[cfe-commits] r42258 - in /cfe/trunk: Lex/Preprocessor.cpp test/Preprocessor/ifdef-recover.c
Chris Lattner
sabre at nondot.org
Sun Sep 23 22:14:57 PDT 2007
Author: lattner
Date: Mon Sep 24 00:14:57 2007
New Revision: 42258
URL: http://llvm.org/viewvc/llvm-project?rev=42258&view=rev
Log:
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.
Added:
cfe/trunk/test/Preprocessor/ifdef-recover.c
Modified:
cfe/trunk/Lex/Preprocessor.cpp
Modified: cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Preprocessor.cpp?rev=42258&r1=42257&r2=42258&view=diff
==============================================================================
--- cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/Lex/Preprocessor.cpp Mon Sep 24 00:14:57 2007
@@ -2121,8 +2121,13 @@
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");
Added: cfe/trunk/test/Preprocessor/ifdef-recover.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/ifdef-recover.c?rev=42258&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/ifdef-recover.c (added)
+++ cfe/trunk/test/Preprocessor/ifdef-recover.c Mon Sep 24 00:14:57 2007
@@ -0,0 +1,7 @@
+/* RUN: clang %s 2>&1 | grep error: | count 1
+ */
+
+#ifdef
+
+#endif
+
More information about the cfe-commits
mailing list