[cfe-commits] r144762 - in /cfe/trunk: test/Index/error-on-deserialized.c tools/libclang/CIndexDiagnostic.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Nov 15 18:34:55 PST 2011
Author: akirtzidis
Date: Tue Nov 15 20:34:55 2011
New Revision: 144762
URL: http://llvm.org/viewvc/llvm-project?rev=144762&view=rev
Log:
[libclang] In lazyCreateDiags, recreate the diagnostic set if the number of diagnostics
in the ASTUnit changed.
Added:
cfe/trunk/test/Index/error-on-deserialized.c
Modified:
cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
Added: cfe/trunk/test/Index/error-on-deserialized.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/error-on-deserialized.c?rev=144762&view=auto
==============================================================================
--- cfe/trunk/test/Index/error-on-deserialized.c (added)
+++ cfe/trunk/test/Index/error-on-deserialized.c Tue Nov 15 20:34:55 2011
@@ -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
Modified: cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexDiagnostic.cpp?rev=144762&r1=144761&r2=144762&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexDiagnostic.cpp Tue Nov 15 20:34:55 2011
@@ -39,9 +39,22 @@
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 @@
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) {
More information about the cfe-commits
mailing list