aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaelyn Uhrain <rikka@google.com>2012-06-20 00:36:03 +0000
committerKaelyn Uhrain <rikka@google.com>2012-06-20 00:36:03 +0000
commitda01f62cdfb0995db355c61d96d45b0f1d790b3d (patch)
treec402506a6974a2bef624f39fbad0a5fa69c14e5d
parentaa0cd85838f2a024e589ea4e8c2094130065af21 (diff)
Add the PCH file name to the message about not being able to read the PCH.
Also add a couple of unit tests to check the invalid-PCH error messages to satisfy PR4568 and for the assertion (introduced in r149918 and fixed in r158769) that would cause clang to crash when given an empty PCH. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158772 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSerializationKinds.td2
-rw-r--r--lib/Serialization/ASTReader.cpp2
-rw-r--r--test/PCH/badpch-dir.h.gch/.keep0
-rw-r--r--test/PCH/badpch-empty.h.gch0
-rw-r--r--test/PCH/badpch.c13
5 files changed, 15 insertions, 2 deletions
diff --git a/include/clang/Basic/DiagnosticSerializationKinds.td b/include/clang/Basic/DiagnosticSerializationKinds.td
index 6e27f3490f..a440e806d7 100644
--- a/include/clang/Basic/DiagnosticSerializationKinds.td
+++ b/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -10,7 +10,7 @@
let Component = "Serialization" in {
def err_fe_unable_to_read_pch_file : Error<
- "unable to read PCH file: '%0'">;
+ "unable to read PCH file %0: '%1'">;
def err_fe_not_a_pch_file : Error<
"input is not a PCH file: '%0'">;
def err_fe_pch_malformed : Error<
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index f5aa74ea98..da031575a2 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -3001,7 +3001,7 @@ std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName,
OwningPtr<llvm::MemoryBuffer> Buffer;
Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr));
if (!Buffer) {
- Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr;
+ Diags.Report(diag::err_fe_unable_to_read_pch_file) << ASTFileName << ErrStr;
return std::string();
}
diff --git a/test/PCH/badpch-dir.h.gch/.keep b/test/PCH/badpch-dir.h.gch/.keep
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/PCH/badpch-dir.h.gch/.keep
diff --git a/test/PCH/badpch-empty.h.gch b/test/PCH/badpch-empty.h.gch
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/PCH/badpch-empty.h.gch
diff --git a/test/PCH/badpch.c b/test/PCH/badpch.c
new file mode 100644
index 0000000000..e687ef3246
--- /dev/null
+++ b/test/PCH/badpch.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -include-pch %S/badpch-empty.h.gch %s 2>&1 | FileCheck -check-prefix=CHECK-EMPTY %s
+// RUN: %clang_cc1 -fsyntax-only -include-pch %S/badpch-dir.h.gch %s 2>&1 | FileCheck -check-prefix=CHECK-DIR %s
+
+// The purpose of this test is to verify that various invalid PCH files are
+// reported as such.
+
+// PR4568: The messages were much improved since the bug was filed on
+// 2009-07-16, though in the case of the PCH being a directory, the error
+// message still did not contain the name of the PCH. Also, r149918 which was
+// submitted on 2012-02-06 introduced a segfault in the case where the PCH is
+// an empty file and clang was built with assertions.
+// CHECK-EMPTY: error: input is not a PCH file: '{{.*[/\\]}}badpch-empty.h.gch'
+// CHECK-DIR: error: unable to read PCH file {{.*[/\\]}}badpch-dir.h.gch: