Skip to content

[Modules][Diagnostic] Don't claim a METADATA mismatch is always in PCH file. #101280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions clang/include/clang/Basic/DiagnosticSerializationKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion clang/test/Index/pch-with-errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Modules/load-module-with-errors.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading