]> granicus.if.org Git - clang/commitdiff
Fix a crash when ASTReader emits diagnostic when another one is in flight. Fixes...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 25 Apr 2011 22:23:56 +0000 (22:23 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 25 Apr 2011 22:23:56 +0000 (22:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130162 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Serialization/ASTReader.h
lib/Serialization/ASTReader.cpp
test/PCH/modified-header-crash.c [new file with mode: 0644]
test/PCH/modified-header-crash.h [new file with mode: 0644]

index ce2c07553873c42b70ce5100099287b4e47724d5..c821df85ff9111beafd22a364294e44eb533d193 100644 (file)
@@ -811,7 +811,9 @@ private:
   ///
   /// 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
index addd73ba356669a0d12c9c292340c94208ef27e6..03d9a05f3e3cfc67be098863931feabe4e9edceb 100644 (file)
@@ -957,8 +957,16 @@ bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor,
   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 @@ ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) {
          || (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;
     }
 
diff --git a/test/PCH/modified-header-crash.c b/test/PCH/modified-header-crash.c
new file mode 100644 (file)
index 0000000..0b6dc7a
--- /dev/null
@@ -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;
+}
diff --git a/test/PCH/modified-header-crash.h b/test/PCH/modified-header-crash.h
new file mode 100644 (file)
index 0000000..971746e
--- /dev/null
@@ -0,0 +1 @@
+int foo;