Author: rsmith Date: Thu May 24 13:03:51 2018 New Revision: 333220 URL: http://llvm.org/viewvc/llvm-project?rev=333220&view=rev Log: Improve diagnostics for config mismatches with -fmodule-file.
Unless the user uses -Wno-module-file-config-mismatch (or -Wno-error=...), allow the AST reader to produce errors describing the nature of the config mismatch. Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td cfe/trunk/lib/Frontend/CompilerInstance.cpp cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp cfe/trunk/test/Modules/merge-target-features.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=333220&r1=333219&r2=333220&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Thu May 24 13:03:51 2018 @@ -38,8 +38,8 @@ def err_pch_targetopt_mismatch : Error< "PCH file was compiled for the %0 '%1' but the current translation " "unit is being compiled for target '%2'">; def err_pch_targetopt_feature_mismatch : Error< - "%select{AST file|current translation unit}0 was compiled with the target " - "feature'%1' but the %select{current translation unit is|AST file was}0 " + "%select{AST file was|current translation unit is}0 compiled with the target " + "feature '%1' but the %select{current translation unit is|AST file was}0 " "not">; def err_pch_langopt_mismatch : Error<"%0 was %select{disabled|enabled}1 in " "PCH file but is currently %select{disabled|enabled}2">; Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=333220&r1=333219&r2=333220&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu May 24 13:03:51 2018 @@ -1602,15 +1602,22 @@ bool CompilerInstance::loadModuleFile(St if (!ModuleManager) createModuleManager(); + // If -Wmodule-file-config-mismatch is mapped as an error or worse, allow the + // ASTReader to diagnose it, since it can produce better errors that we can. + bool ConfigMismatchIsRecoverable = + getDiagnostics().getDiagnosticLevel(diag::warn_module_config_mismatch, + SourceLocation()) + <= DiagnosticsEngine::Warning; + auto Listener = llvm::make_unique<ReadModuleNames>(*this); auto &ListenerRef = *Listener; ASTReader::ListenerScope ReadModuleNamesListener(*ModuleManager, std::move(Listener)); // Try to load the module file. - switch (ModuleManager->ReadAST(FileName, serialization::MK_ExplicitModule, - SourceLocation(), - ASTReader::ARR_ConfigurationMismatch)) { + switch (ModuleManager->ReadAST( + FileName, serialization::MK_ExplicitModule, SourceLocation(), + ConfigMismatchIsRecoverable ? ASTReader::ARR_ConfigurationMismatch : 0)) { case ASTReader::Success: // We successfully loaded the module file; remember the set of provided // modules so that we don't try to load implicit modules for them. Modified: cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp?rev=333220&r1=333219&r2=333220&view=diff ============================================================================== --- cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp (original) +++ cfe/trunk/test/Modules/check-for-sanitizer-feature.cpp Thu May 24 13:03:51 2018 @@ -43,7 +43,7 @@ // // Import the PCH without ASan enabled (we expect an error). // RUN: not %clang_cc1 -x c -include-pch %t.asan_pch %s -verify 2>&1 | FileCheck %s --check-prefix=PCH_MISMATCH -// PCH_MISMATCH: AST file was compiled with the target feature'-fsanitize=address' but the current translation unit is not +// PCH_MISMATCH: AST file was compiled with the target feature '-fsanitize=address' but the current translation unit is not // // Emit a PCH with UBSan enabled. // RUN: %clang_cc1 -x c -fsanitize=null %S/Inputs/check-for-sanitizer-feature/check.h -emit-pch -o %t.ubsan_pch Modified: cfe/trunk/test/Modules/merge-target-features.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-target-features.cpp?rev=333220&r1=333219&r2=333220&view=diff ============================================================================== --- cfe/trunk/test/Modules/merge-target-features.cpp (original) +++ cfe/trunk/test/Modules/merge-target-features.cpp Thu May 24 13:03:51 2018 @@ -19,10 +19,9 @@ // RUN: -triple i386-unknown-unknown \ // RUN: -target-cpu i386 \ // RUN: -fsyntax-only merge-target-features.cpp 2>&1 \ -// RUN: | FileCheck --check-prefix=SUBSET %s -// SUBSET-NOT: error: +// RUN: | FileCheck --check-prefix=SUBSET --implicit-check-not=error: %s +// SUBSET: error: AST file was compiled with the target feature '+sse2' but the current translation unit is not // SUBSET: error: {{.*}} configuration mismatch -// SUBSET-NOT: error: // // RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \ // RUN: -iquote Inputs/merge-target-features \ @@ -57,10 +56,10 @@ // RUN: -triple i386-unknown-unknown \ // RUN: -target-cpu i386 -target-feature +cx16 \ // RUN: -fsyntax-only merge-target-features.cpp 2>&1 \ -// RUN: | FileCheck --check-prefix=MISMATCH %s -// MISMATCH-NOT: error: +// RUN: | FileCheck --check-prefix=MISMATCH --implicit-check-not=error: %s +// MISMATCH: error: AST file was compiled with the target feature '+sse2' but the current translation unit is not +// MISMATCH: error: current translation unit is compiled with the target feature '+cx16' but the AST file was not // MISMATCH: error: {{.*}} configuration mismatch -// MISMATCH-NOT: error: #include "foo.h" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits