From 8d8f2c20f3e21c7516e5d27293f08283913904d1 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Mon, 25 Apr 2011 22:23:56 +0000 Subject: [PATCH] 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 --- include/clang/Serialization/ASTReader.h | 4 +++- lib/Serialization/ASTReader.cpp | 15 +++++++++++---- test/PCH/modified-header-crash.c | 9 +++++++++ test/PCH/modified-header-crash.h | 1 + 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 test/PCH/modified-header-crash.c create mode 100644 test/PCH/modified-header-crash.h 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; -- 2.50.1