]> granicus.if.org Git - clang/commitdiff
[modules] Allow the error when explicitly loading an incompatible module file
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 16 Oct 2015 23:20:19 +0000 (23:20 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 16 Oct 2015 23:20:19 +0000 (23:20 +0000)
via -fmodule-file= to be turned off; in that case, just include the relevant
files textually. This allows module files to be unconditionally passed to all
compile actions via CXXFLAGS, and to be ignored for rules that specify custom
incompatible flags.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250577 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticFrontendKinds.td
lib/Frontend/CompilerInstance.cpp
test/Modules/merge-target-features.cpp

index 5af989825725b69aa2e3428f7596898fd8879884..28fc3059b2583d2ef224c4b7066ed246e9e4ee56 100644 (file)
@@ -172,6 +172,9 @@ def warn_incompatible_analyzer_plugin_api : Warning<
 def note_incompatible_analyzer_plugin_api : Note<
     "current API version is '%0', but plugin was compiled with version '%1'">;
 
+def warn_module_config_mismatch : Warning<
+  "module file %0 cannot be loaded due to a configuration mismatch with the current "
+  "compilation">, InGroup<DiagGroup<"module-file-config-mismatch">>, DefaultError;
 def err_module_map_not_found : Error<"module map file '%0' not found">, 
   DefaultFatal;
 def err_missing_module_name : Error<
index 740524ce2c527c1c14377c04f4af88eb4b2c02e7..8220a6e492570aff271caae9c3576ef3a4cdfc01 100644 (file)
@@ -1335,15 +1335,24 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {
                                                    std::move(Listener));
 
   // Try to load the module file.
-  if (ModuleManager->ReadAST(FileName, serialization::MK_ExplicitModule,
-                             SourceLocation(), ASTReader::ARR_None)
-          != ASTReader::Success)
-    return false;
-
+  switch (ModuleManager->ReadAST(FileName, serialization::MK_ExplicitModule,
+                                 SourceLocation(),
+                                 ASTReader::ARR_ConfigurationMismatch)) {
+  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.
   ListenerRef.registerAll();
   return true;
+
+  case ASTReader::ConfigurationMismatch:
+    // Ignore unusable module files.
+    getDiagnostics().Report(SourceLocation(), diag::warn_module_config_mismatch)
+        << FileName;
+    return true;
+
+  default:
+    return false;
+  }
 }
 
 ModuleLoadResult
index 938715dd6b11a5b75866b4711ecb7b46a82420b5..0ca5679ad160c663e0bc03201dbd612f5b499ff5 100644 (file)
@@ -20,7 +20,7 @@
 // RUN:   -target-cpu i386 \
 // RUN:   -fsyntax-only merge-target-features.cpp 2>&1 \
 // RUN:   | FileCheck --check-prefix=SUBSET %s
-// SUBSET: AST file was compiled with the target feature'+sse2' but the current translation unit is not
+// SUBSET: error: {{.*}} configuration mismatch
 //
 // RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
 // RUN:   -iquote Inputs/merge-target-features \
@@ -56,8 +56,7 @@
 // RUN:   -target-cpu i386 -target-feature +cx16 \
 // RUN:   -fsyntax-only merge-target-features.cpp 2>&1 \
 // RUN:   | FileCheck --check-prefix=MISMATCH %s
-// MISMATCH: AST file was compiled with the target feature'+sse2' but the current translation unit is not
-// MISMATCH: current translation unit was compiled with the target feature'+cx16' but the AST file was not
+// MISMATCH: error: {{.*}} configuration mismatch
 
 #include "foo.h"