summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/Lex/Preprocessor.cpp7
-rw-r--r--clang/test/Preprocessor/ifdef-recover.c7
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
+
OpenPOWER on IntegriCloud