]> granicus.if.org Git - clang/commitdiff
[libclang] Fix crash when a #pragma diagnostic is included in the preamble.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 3 Nov 2011 20:28:19 +0000 (20:28 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 3 Nov 2011 20:28:19 +0000 (20:28 +0000)
A PCH file keeps track of #pragma diagnostics state; when loading the preamble, they conflicted
with the #pragma diagnostic state already present in the DiagnosticsEngine object due to
parsing the preamble.

Fix this by clearing the state of the DiagnosticsEngine object.
Fixes rdar://10363572 && http://llvm.org/PR11254.

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

lib/Frontend/ASTUnit.cpp
test/Index/pragma-diag-reparse.c

index 015e92dfcd77a96165c768bb3d5672e6f36d7f2c..0dd3a38da47f4d05d5a595af7788923ac861dc64 100644 (file)
@@ -1388,8 +1388,6 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
 
         // Set the state of the diagnostic object to mimic its state
         // after parsing the preamble.
-        // FIXME: This won't catch any #pragma push warning changes that
-        // have occurred in the preamble.
         getDiagnostics().Reset();
         ProcessWarningOptions(getDiagnostics(), 
                               PreambleInvocation->getDiagnosticOpts());
@@ -1940,11 +1938,9 @@ bool ASTUnit::Reparse(RemappedFile *RemappedFiles, unsigned NumRemappedFiles) {
     OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(*Invocation);
     
   // Clear out the diagnostics state.
-  if (!OverrideMainBuffer) {
-    getDiagnostics().Reset();
-    ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts());
-  }
-  
+  getDiagnostics().Reset();
+  ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts());
+
   // Parse the sources
   bool Result = Parse(OverrideMainBuffer);
   
index efe59b17784191cb393866ddf78ccbf4dfa85372..1dccd59523f12c25bd08210bd4a75e8454e4e089 100644 (file)
@@ -1,13 +1,18 @@
-// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 5 local %s | FileCheck %s
+#pragma clang diagnostic ignored "-Wtautological-compare"
 
 int main (int argc, const char * argv[])
 {
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
-  int x;
+  int x=0;
 #pragma clang diagnostic pop
 
-  return 0;
+  return x;
 }
 
-// CHECK: pragma-diag-reparse.c:7:7: VarDecl=x:7:7 (Definition) Extent=[7:3 - 7:8]
+void foo() { int b=0; while (b==b); }
+
+// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_FAILONERROR=1 c-index-test -test-load-source-reparse 5 local \
+// RUN:   %s -Wall -Werror | FileCheck %s
+
+// CHECK: pragma-diag-reparse.c:7:7: VarDecl=x:7:7 (Definition) Extent=[7:3 - 7:10]