aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-11-16 02:34:55 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-11-16 02:34:55 +0000
commit220b45c95edc0ea86cd157426e0edc7f6a288620 (patch)
tree2027b4e759c790e1c26aab6771473ec7ce1fdbe3
parent32380594b6774af451cf34af79b086d6f920d052 (diff)
[libclang] In lazyCreateDiags, recreate the diagnostic set if the number of diagnostics
in the ASTUnit changed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144762 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--test/Index/error-on-deserialized.c13
-rw-r--r--tools/libclang/CIndexDiagnostic.cpp19
2 files changed, 29 insertions, 3 deletions
diff --git a/test/Index/error-on-deserialized.c b/test/Index/error-on-deserialized.c
new file mode 100644
index 0000000000..8ba828328e
--- /dev/null
+++ b/test/Index/error-on-deserialized.c
@@ -0,0 +1,13 @@
+
+#include "targeted-top.h"
+
+// This tests that we will correctly error out on the deserialized decl.
+
+// RUN: c-index-test -write-pch %t.h.pch %S/targeted-top.h
+// RUN: env CINDEXTEST_FAILONERROR=1 not c-index-test -cursor-at=%S/targeted-nested1.h:2:16 %s -include %t.h \
+// RUN: -Xclang -error-on-deserialized-decl=NestedVar1
+// RUN: env CINDEXTEST_FAILONERROR=1 c-index-test -cursor-at=%S/targeted-nested1.h:2:16 %s -include %t.h \
+// RUN: -Xclang -error-on-deserialized-decl=NestedVar1 2>&1 \
+// RUN: | FileCheck %s
+
+// CHECK: error: NestedVar1 was deserialized
diff --git a/tools/libclang/CIndexDiagnostic.cpp b/tools/libclang/CIndexDiagnostic.cpp
index 436ea37038..50641fad1c 100644
--- a/tools/libclang/CIndexDiagnostic.cpp
+++ b/tools/libclang/CIndexDiagnostic.cpp
@@ -39,9 +39,22 @@ CXDiagnosticSetImpl::~CXDiagnosticSetImpl() {
CXDiagnosticImpl::~CXDiagnosticImpl() {}
-static CXDiagnosticSetImpl *lazyCreateDiags(CXTranslationUnit TU) {
+static CXDiagnosticSetImpl *lazyCreateDiags(CXTranslationUnit TU,
+ bool checkIfChanged = false) {
+ ASTUnit *AU = static_cast<ASTUnit *>(TU->TUData);
+
+ if (TU->Diagnostics && checkIfChanged) {
+ CXDiagnosticSetImpl *
+ Set = static_cast<CXDiagnosticSetImpl*>(TU->Diagnostics);
+ if (AU->stored_diag_size() != Set->getNumDiagnostics()) {
+ // Diagnostics in the ASTUnit were updated, reset the associated
+ // diagnostics.
+ delete Set;
+ TU->Diagnostics = 0;
+ }
+ }
+
if (!TU->Diagnostics) {
- ASTUnit *AU = static_cast<ASTUnit *>(TU->TUData);
CXDiagnosticSetImpl *Set = new CXDiagnosticSetImpl();
TU->Diagnostics = Set;
@@ -63,7 +76,7 @@ extern "C" {
unsigned clang_getNumDiagnostics(CXTranslationUnit Unit) {
if (!Unit->TUData)
return 0;
- return lazyCreateDiags(Unit)->getNumDiagnostics();
+ return lazyCreateDiags(Unit, /*checkIfChanged=*/true)->getNumDiagnostics();
}
CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, unsigned Index) {