[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
This commit is contained in:
Volodymyr Sapsai 2024-07-31 10:38:32 -07:00 committed by GitHub
parent 35a2e6d24b
commit f9827e67ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 16 deletions

View File

@ -50,14 +50,14 @@ def warn_pch_vfsoverlay_mismatch : Warning<
def note_pch_vfsoverlay_files : Note<"%select{PCH|current translation unit}0 has the following VFS overlays:\n%1">;
def note_pch_vfsoverlay_empty : Note<"%select{PCH|current translation unit}0 has no VFS overlays">;
def err_pch_version_too_old : Error<
"PCH file uses an older PCH format that is no longer supported">;
def err_pch_version_too_new : Error<
"PCH file uses a newer PCH format that cannot be read">;
def err_pch_different_branch : Error<
"PCH file built from a different branch (%0) than the compiler (%1)">;
def err_pch_with_compiler_errors : Error<
"PCH file contains compiler errors">;
def err_ast_file_version_too_old : Error<
"%select{PCH|module|AST}0 file '%1' uses an older PCH format that is no longer supported">;
def err_ast_file_version_too_new : Error<
"%select{PCH|module|AST}0 file '%1' uses a newer PCH format that cannot be read">;
def err_ast_file_different_branch : Error<
"%select{PCH|module|AST}0 file '%1' built from a different branch (%2) than the compiler (%3)">;
def err_ast_file_with_compiler_errors : Error<
"%select{PCH|module|AST}0 file '%1' contains compiler errors">;
def err_module_file_conflict : Error<
"module '%0' is defined in both '%1' and '%2'">, DefaultFatal;

View File

@ -3023,8 +3023,9 @@ ASTReader::ReadControlBlock(ModuleFile &F,
case METADATA: {
if (Record[0] != VERSION_MAJOR && !DisableValidation) {
if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
Diag(Record[0] < VERSION_MAJOR? diag::err_pch_version_too_old
: diag::err_pch_version_too_new);
Diag(Record[0] < VERSION_MAJOR ? diag::err_ast_file_version_too_old
: diag::err_ast_file_version_too_new)
<< moduleKindForDiagnostic(F.Kind) << F.FileName;
return VersionMismatch;
}
@ -3037,7 +3038,8 @@ ASTReader::ReadControlBlock(ModuleFile &F,
return OutOfDate;
if (!AllowASTWithCompilerErrors) {
Diag(diag::err_pch_with_compiler_errors);
Diag(diag::err_ast_file_with_compiler_errors)
<< moduleKindForDiagnostic(F.Kind) << F.FileName;
return HadErrors;
}
}
@ -3060,7 +3062,9 @@ ASTReader::ReadControlBlock(ModuleFile &F,
StringRef ASTBranch = Blob;
if (StringRef(CurBranch) != ASTBranch && !DisableValidation) {
if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
Diag(diag::err_pch_different_branch) << ASTBranch << CurBranch;
Diag(diag::err_ast_file_different_branch)
<< moduleKindForDiagnostic(F.Kind) << F.FileName << ASTBranch
<< CurBranch;
return VersionMismatch;
}
break;
@ -4827,7 +4831,8 @@ ASTReader::ReadASTCore(StringRef FileName,
case AST_BLOCK_ID:
if (!HaveReadControlBlock) {
if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
Diag(diag::err_pch_version_too_old);
Diag(diag::err_ast_file_version_too_old)
<< moduleKindForDiagnostic(Type) << FileName;
return VersionMismatch;
}

View File

@ -38,7 +38,7 @@ void foo(void) {
// CHECK-INDEX: [indexEntityReference]: kind: function | name: erroneous
// RUN: not %clang -fsyntax-only %s -include %t.h 2>&1 | FileCheck -check-prefix=PCH-ERR %s
// PCH-ERR: error: PCH file contains compiler errors
// PCH-ERR: error: PCH file '{{.*}}' contains compiler errors
// RUN: not c-index-test -write-pch %t.pch foobar.c 2>&1 | FileCheck -check-prefix=NONEXISTENT %s
// NONEXISTENT: Unable to load translation unit

View File

@ -1,7 +1,7 @@
// Note: the run lines follow their respective tests, since line/column
// matter in this test.
// pcherror-error@* {{PCH file contains compiler errors}}
// pcherror-error-re@* {{module file '{{.*}}use_error_a.pcm' contains compiler errors}}
@import use_error_a; // notallowerror-error {{could not build module 'use_error_a'}}
@import use_error_b;
// expected-no-diagnostics
@ -61,7 +61,7 @@ void test(Error *x) {
// RUN: -fmodule-file=%t/prebuilt/use_error_a.pcm \
// RUN: -fmodule-file=%t/prebuilt/use_error_b.pcm \
// RUN: -fmodules-cache-path=%t 2>&1 | \
// RUN: grep "PCH file contains compiler errors"
// RUN: grep "module file .* contains compiler errors"
// Shouldn't build the cached modules (that have errors) when not allowing
// errors