[cfe-commits] r130162 - in /cfe/trunk: include/clang/Serialization/ASTReader.h lib/Serialization/ASTReader.cpp test/PCH/modified-header-crash.c test/PCH/modified-header-crash.h

Argyrios Kyrtzidis akyrtzi at gmail.com
Mon Apr 25 15:23:56 PDT 2011


Author: akirtzidis
Date: Mon Apr 25 17:23:56 2011
New Revision: 130162

URL: http://llvm.org/viewvc/llvm-project?rev=130162&view=rev
Log:
Fix a crash when ASTReader emits diagnostic when another one is in flight. Fixes rdar//9334563.

Added:
    cfe/trunk/test/PCH/modified-header-crash.c
    cfe/trunk/test/PCH/modified-header-crash.h
Modified:
    cfe/trunk/include/clang/Serialization/ASTReader.h
    cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=130162&r1=130161&r2=130162&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Mon Apr 25 17:23:56 2011
@@ -811,7 +811,9 @@
   ///
   /// This routine should only be used for fatal errors that have to
   /// do with non-routine failures (e.g., corrupted AST file).
-  void Error(const char *Msg);
+  void Error(llvm::StringRef Msg);
+  void Error(unsigned DiagID, llvm::StringRef Arg1 = llvm::StringRef(),
+             llvm::StringRef Arg2 = llvm::StringRef());
 
   ASTReader(const ASTReader&); // do not implement
   ASTReader &operator=(const ASTReader &); // do not implement

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=130162&r1=130161&r2=130162&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon Apr 25 17:23:56 2011
@@ -957,8 +957,16 @@
   return false;
 }
 
-void ASTReader::Error(const char *Msg) {
-  Diag(diag::err_fe_pch_malformed) << Msg;
+void ASTReader::Error(llvm::StringRef Msg) {
+  Error(diag::err_fe_pch_malformed, Msg);
+}
+
+void ASTReader::Error(unsigned DiagID,
+                      llvm::StringRef Arg1, llvm::StringRef Arg2) {
+  if (Diags.isDiagnosticInFlight())
+    Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2);
+  else
+    Diag(DiagID) << Arg1 << Arg2;
 }
 
 /// \brief Tell the AST listener about the predefines buffers in the chain.
@@ -1310,8 +1318,7 @@
          || (time_t)Record[5] != File->getModificationTime()
 #endif
         )) {
-      Diag(diag::err_fe_pch_file_modified)
-        << Filename;
+      Error(diag::err_fe_pch_file_modified, Filename);
       return Failure;
     }
 

Added: cfe/trunk/test/PCH/modified-header-crash.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/modified-header-crash.c?rev=130162&view=auto
==============================================================================
--- cfe/trunk/test/PCH/modified-header-crash.c (added)
+++ cfe/trunk/test/PCH/modified-header-crash.c Mon Apr 25 17:23:56 2011
@@ -0,0 +1,9 @@
+// Don't crash.
+
+// RUN: %clang_cc1 -DCAKE -x c-header %S/modified-header-crash.h -emit-pch -o %t
+// RUN: touch %S/modified-header-crash.h
+// RUN: not %clang_cc1 %s -include-pch %t -fsyntax-only
+
+void f(void) {
+  foo = 3;
+}

Added: cfe/trunk/test/PCH/modified-header-crash.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/modified-header-crash.h?rev=130162&view=auto
==============================================================================
--- cfe/trunk/test/PCH/modified-header-crash.h (added)
+++ cfe/trunk/test/PCH/modified-header-crash.h Mon Apr 25 17:23:56 2011
@@ -0,0 +1 @@
+int foo;





More information about the cfe-commits mailing list