Author: ibiryukov
Date: Tue Sep 12 01:35:57 2017
New Revision: 313014

URL: http://llvm.org/viewvc/llvm-project?rev=313014&view=rev
Log:
Fix recording preamble's conditional stack in skipped PP branches.

Summary:
This fixes PR34547.
`Lexer::LexEndOfFile` handles recording of ConditionalStack for
preamble and reporting errors about unmatched conditionalal PP
directives.
However, SkipExcludedConditionalBlock contianed duplicated logic for
reporting errors and clearing ConditionalStack, but not for preamble
recording.

This fix removes error reporting logic from
`SkipExcludedConditionalBlock`, unmatched PP conditionals are now
reported inside `Lexer::LexEndOfFile`.

Reviewers: erikjv, klimek, bkramer

Reviewed By: erikjv

Subscribers: nik, cfe-commits

Differential Revision: https://reviews.llvm.org/D37700

Added:
    cfe/trunk/test/Index/preamble-conditionals-inverted-with-error.cpp
    cfe/trunk/test/Index/preamble-conditionals-inverted.cpp
Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=313014&r1=313013&r2=313014&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Sep 12 01:35:57 2017
@@ -383,15 +383,8 @@ void Preprocessor::SkipExcludedCondition
 
     // If this is the end of the buffer, we have an error.
     if (Tok.is(tok::eof)) {
-      // Emit errors for each unterminated conditional on the stack, including
-      // the current one.
-      while (!CurPPLexer->ConditionalStack.empty()) {
-        if (CurLexer->getFileLoc() != CodeCompletionFileLoc)
-          Diag(CurPPLexer->ConditionalStack.back().IfLoc,
-               diag::err_pp_unterminated_conditional);
-        CurPPLexer->ConditionalStack.pop_back();
-      }
-
+      // We don't emit errors for unterminated conditionals here,
+      // Lexer::LexEndOfFile can do that propertly.
       // Just return and let the caller lex after this #include.
       break;
     }

Added: cfe/trunk/test/Index/preamble-conditionals-inverted-with-error.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/preamble-conditionals-inverted-with-error.cpp?rev=313014&view=auto
==============================================================================
--- cfe/trunk/test/Index/preamble-conditionals-inverted-with-error.cpp (added)
+++ cfe/trunk/test/Index/preamble-conditionals-inverted-with-error.cpp Tue Sep 
12 01:35:57 2017
@@ -0,0 +1,8 @@
+// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 5 \
+// RUN:                                       local -std=c++14 %s 2>&1 \
+// RUN: | FileCheck %s
+#ifdef FOO_H
+
+void foo();
+
+// CHECK: preamble-conditionals-inverted-with-error.cpp:4:2: error: 
unterminated conditional directive

Added: cfe/trunk/test/Index/preamble-conditionals-inverted.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/preamble-conditionals-inverted.cpp?rev=313014&view=auto
==============================================================================
--- cfe/trunk/test/Index/preamble-conditionals-inverted.cpp (added)
+++ cfe/trunk/test/Index/preamble-conditionals-inverted.cpp Tue Sep 12 01:35:57 
2017
@@ -0,0 +1,8 @@
+// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 5 \
+// RUN:                                       local -std=c++14 %s 2>&1 \
+// RUN: | FileCheck %s --implicit-check-not "error:"
+#ifdef FOO_H
+
+void foo();
+
+#endif


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to