]> granicus.if.org Git - clang/commitdiff
Fix recording preamble's conditional stack in skipped PP branches.
authorIlya Biryukov <ibiryukov@google.com>
Tue, 12 Sep 2017 08:35:57 +0000 (08:35 +0000)
committerIlya Biryukov <ibiryukov@google.com>
Tue, 12 Sep 2017 08:35:57 +0000 (08:35 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313014 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp
test/Index/preamble-conditionals-inverted-with-error.cpp [new file with mode: 0644]
test/Index/preamble-conditionals-inverted.cpp [new file with mode: 0644]

index 556e76356da47212f5a0e4b7bef18b8c59d01d69..eb9f11f3d4df8972dd71b6de77f3736280c2393a 100644 (file)
@@ -383,15 +383,8 @@ void Preprocessor::SkipExcludedConditionalBlock(const Token &HashToken,
 
     // 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;
     }
diff --git a/test/Index/preamble-conditionals-inverted-with-error.cpp b/test/Index/preamble-conditionals-inverted-with-error.cpp
new file mode 100644 (file)
index 0000000..95b0695
--- /dev/null
@@ -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
diff --git a/test/Index/preamble-conditionals-inverted.cpp b/test/Index/preamble-conditionals-inverted.cpp
new file mode 100644 (file)
index 0000000..1d67ccb
--- /dev/null
@@ -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