From da01f62cdfb0995db355c61d96d45b0f1d790b3d Mon Sep 17 00:00:00 2001 From: Kaelyn Uhrain Date: Wed, 20 Jun 2012 00:36:03 +0000 Subject: [PATCH] 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 --- include/clang/Basic/DiagnosticSerializationKinds.td | 2 +- lib/Serialization/ASTReader.cpp | 2 +- test/PCH/badpch-dir.h.gch/.keep | 0 test/PCH/badpch-empty.h.gch | 0 test/PCH/badpch.c | 13 +++++++++++++ 5 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/PCH/badpch-dir.h.gch/.keep create mode 100644 test/PCH/badpch-empty.h.gch create mode 100644 test/PCH/badpch.c 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 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 diff --git a/test/PCH/badpch-empty.h.gch b/test/PCH/badpch-empty.h.gch new file mode 100644 index 0000000000..e69de29bb2 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: -- 2.40.0