aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-04-25 22:23:56 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-04-25 22:23:56 +0000
commit8d8f2c20f3e21c7516e5d27293f08283913904d1 (patch)
tree6ace3034c2e79b9a123890fddbf954b12aa76e78
parent357f6ee9f1f6f8e5027377cb3e5907c62c4fe3df (diff)
Fix a crash when ASTReader emits diagnostic when another one is in flight. Fixes rdar//9334563.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130162 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Serialization/ASTReader.h4
-rw-r--r--lib/Serialization/ASTReader.cpp15
-rw-r--r--test/PCH/modified-header-crash.c9
-rw-r--r--test/PCH/modified-header-crash.h1
4 files changed, 24 insertions, 5 deletions
diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h
index ce2c075538..c821df85ff 100644
--- a/include/clang/Serialization/ASTReader.h
+++ b/include/clang/Serialization/ASTReader.h
@@ -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
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index addd73ba35..03d9a05f3e 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -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
index 0000000000..0b6dc7aaf0
--- /dev/null
+++ b/test/PCH/modified-header-crash.c
@@ -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
index 0000000000..971746e3bd
--- /dev/null
+++ b/test/PCH/modified-header-crash.h
@@ -0,0 +1 @@
+int foo;