Skip to content

Commit f9827e6

Browse files
authored
[Modules][Diagnostic] Don't claim a METADATA mismatch is always in PCH file. (#101280)
You can provide more than one AST file as an input. Emit a path for a file with a problem, so you can disambiguate between multiple files. rdar://65005546
1 parent 35a2e6d commit f9827e6

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

clang/include/clang/Basic/DiagnosticSerializationKinds.td

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ def warn_pch_vfsoverlay_mismatch : Warning<
5050
def note_pch_vfsoverlay_files : Note<"%select{PCH|current translation unit}0 has the following VFS overlays:\n%1">;
5151
def note_pch_vfsoverlay_empty : Note<"%select{PCH|current translation unit}0 has no VFS overlays">;
5252

53-
def err_pch_version_too_old : Error<
54-
"PCH file uses an older PCH format that is no longer supported">;
55-
def err_pch_version_too_new : Error<
56-
"PCH file uses a newer PCH format that cannot be read">;
57-
def err_pch_different_branch : Error<
58-
"PCH file built from a different branch (%0) than the compiler (%1)">;
59-
def err_pch_with_compiler_errors : Error<
60-
"PCH file contains compiler errors">;
53+
def err_ast_file_version_too_old : Error<
54+
"%select{PCH|module|AST}0 file '%1' uses an older PCH format that is no longer supported">;
55+
def err_ast_file_version_too_new : Error<
56+
"%select{PCH|module|AST}0 file '%1' uses a newer PCH format that cannot be read">;
57+
def err_ast_file_different_branch : Error<
58+
"%select{PCH|module|AST}0 file '%1' built from a different branch (%2) than the compiler (%3)">;
59+
def err_ast_file_with_compiler_errors : Error<
60+
"%select{PCH|module|AST}0 file '%1' contains compiler errors">;
6161

6262
def err_module_file_conflict : Error<
6363
"module '%0' is defined in both '%1' and '%2'">, DefaultFatal;

clang/lib/Serialization/ASTReader.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,8 +3023,9 @@ ASTReader::ReadControlBlock(ModuleFile &F,
30233023
case METADATA: {
30243024
if (Record[0] != VERSION_MAJOR && !DisableValidation) {
30253025
if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
3026-
Diag(Record[0] < VERSION_MAJOR? diag::err_pch_version_too_old
3027-
: diag::err_pch_version_too_new);
3026+
Diag(Record[0] < VERSION_MAJOR ? diag::err_ast_file_version_too_old
3027+
: diag::err_ast_file_version_too_new)
3028+
<< moduleKindForDiagnostic(F.Kind) << F.FileName;
30283029
return VersionMismatch;
30293030
}
30303031

@@ -3037,7 +3038,8 @@ ASTReader::ReadControlBlock(ModuleFile &F,
30373038
return OutOfDate;
30383039

30393040
if (!AllowASTWithCompilerErrors) {
3040-
Diag(diag::err_pch_with_compiler_errors);
3041+
Diag(diag::err_ast_file_with_compiler_errors)
3042+
<< moduleKindForDiagnostic(F.Kind) << F.FileName;
30413043
return HadErrors;
30423044
}
30433045
}
@@ -3060,7 +3062,9 @@ ASTReader::ReadControlBlock(ModuleFile &F,
30603062
StringRef ASTBranch = Blob;
30613063
if (StringRef(CurBranch) != ASTBranch && !DisableValidation) {
30623064
if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
3063-
Diag(diag::err_pch_different_branch) << ASTBranch << CurBranch;
3065+
Diag(diag::err_ast_file_different_branch)
3066+
<< moduleKindForDiagnostic(F.Kind) << F.FileName << ASTBranch
3067+
<< CurBranch;
30643068
return VersionMismatch;
30653069
}
30663070
break;
@@ -4827,7 +4831,8 @@ ASTReader::ReadASTCore(StringRef FileName,
48274831
case AST_BLOCK_ID:
48284832
if (!HaveReadControlBlock) {
48294833
if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
4830-
Diag(diag::err_pch_version_too_old);
4834+
Diag(diag::err_ast_file_version_too_old)
4835+
<< moduleKindForDiagnostic(Type) << FileName;
48314836
return VersionMismatch;
48324837
}
48334838

clang/test/Index/pch-with-errors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void foo(void) {
3838
// CHECK-INDEX: [indexEntityReference]: kind: function | name: erroneous
3939

4040
// RUN: not %clang -fsyntax-only %s -include %t.h 2>&1 | FileCheck -check-prefix=PCH-ERR %s
41-
// PCH-ERR: error: PCH file contains compiler errors
41+
// PCH-ERR: error: PCH file '{{.*}}' contains compiler errors
4242

4343
// RUN: not c-index-test -write-pch %t.pch foobar.c 2>&1 | FileCheck -check-prefix=NONEXISTENT %s
4444
// NONEXISTENT: Unable to load translation unit

clang/test/Modules/load-module-with-errors.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Note: the run lines follow their respective tests, since line/column
22
// matter in this test.
33

4-
// pcherror-error@* {{PCH file contains compiler errors}}
4+
// pcherror-error-re@* {{module file '{{.*}}use_error_a.pcm' contains compiler errors}}
55
@import use_error_a; // notallowerror-error {{could not build module 'use_error_a'}}
66
@import use_error_b;
77
// expected-no-diagnostics
@@ -61,7 +61,7 @@ void test(Error *x) {
6161
// RUN: -fmodule-file=%t/prebuilt/use_error_a.pcm \
6262
// RUN: -fmodule-file=%t/prebuilt/use_error_b.pcm \
6363
// RUN: -fmodules-cache-path=%t 2>&1 | \
64-
// RUN: grep "PCH file contains compiler errors"
64+
// RUN: grep "module file .* contains compiler errors"
6565

6666
// Shouldn't build the cached modules (that have errors) when not allowing
6767
// errors

0 commit comments

Comments
 (0)