]> granicus.if.org Git - clang/commitdiff
Fix initial diagnostic state setup for an explicit module with no diagnostic pragmas.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 1 May 2017 22:10:47 +0000 (22:10 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 1 May 2017 22:10:47 +0000 (22:10 +0000)
If a file has no diagnostic pragmas, we build its diagnostic state lazily, but
in this case we never set up the root state to be the diagnostic state in which
the module was originally built, so the diagnostic flags for files in the
module with no diagnostic pragmas were incorrectly based on the user of the
module rather than the diagnostic state when the module was built.

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

lib/Serialization/ASTReader.cpp
test/Modules/Inputs/module.map
test/Modules/diag-flags.cpp [new file with mode: 0644]

index d2e4c5077702e2cc4cd8baf4f413daf7e386f2d2..5312ad118d5bc666d409bc63c6e6d92ccc95ce9b 100644 (file)
@@ -3765,6 +3765,13 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
       SourceMgr.getLoadedSLocEntryByID(Index);
     }
 
+    // Map the original source file ID into the ID space of the current
+    // compilation.
+    if (F.OriginalSourceFileID.isValid()) {
+      F.OriginalSourceFileID = FileID::get(
+          F.SLocEntryBaseID + F.OriginalSourceFileID.getOpaqueValue() - 1);
+    }
+
     // Preload all the pending interesting identifiers by marking them out of
     // date.
     for (auto Offset : F.PreloadIdentifierOffsets) {
@@ -3873,10 +3880,6 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
 
   ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule();
   if (PrimaryModule.OriginalSourceFileID.isValid()) {
-    PrimaryModule.OriginalSourceFileID
-      = FileID::get(PrimaryModule.SLocEntryBaseID
-                    + PrimaryModule.OriginalSourceFileID.getOpaqueValue() - 1);
-
     // If this AST file is a precompiled preamble, then set the
     // preamble file ID of the source manager to the file source file
     // from which the preamble was built.
@@ -5575,6 +5578,13 @@ void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) {
       FirstState = ReadDiagState(
           F.isModule() ? DiagState() : *Diag.DiagStatesByLoc.CurDiagState,
           SourceLocation(), F.isModule());
+
+      // For an explicit module, set up the root buffer of the module to start
+      // with the initial diagnostic state of the module itself, to cover files
+      // that contain no explicit transitions.
+      if (F.isModule())
+        Diag.DiagStatesByLoc.Files[F.OriginalSourceFileID]
+            .StateTransitions.push_back({FirstState, 0});
     }
 
     // Read the state transitions.
index b95eec351e862542945bb20761924343e1ecf809..7416d7008b85050db6313877fc7b0693f0b234cc 100644 (file)
@@ -261,6 +261,10 @@ module config {
   config_macros [exhaustive] WANT_FOO, WANT_BAR
 }
 
+module diag_flags {
+  header "diag_flags.h"
+}
+
 module diag_pragma {
   header "diag_pragma.h"
 }
diff --git a/test/Modules/diag-flags.cpp b/test/Modules/diag-flags.cpp
new file mode 100644 (file)
index 0000000..36222fb
--- /dev/null
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -emit-module -fmodules-cache-path=%t -fmodule-name=diag_flags -x c++ %S/Inputs/module.map -fmodules-ts
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify -fmodules-cache-path=%t -I %S/Inputs %s -fmodules-ts
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify -fmodules-cache-path=%t -I %S/Inputs %s -fmodules-ts -DIMPLICIT_FLAG -Werror=padded
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -emit-module -fmodule-name=diag_flags -x c++ %S/Inputs/module.map -fmodules-ts -o %t/explicit.pcm -Werror=string-plus-int -Wpadded
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify -fmodules-cache-path=%t -I %S/Inputs %s -fmodules-ts -DEXPLICIT_FLAG -fmodule-file=%t/explicit.pcm
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify -fmodules-cache-path=%t -I %S/Inputs %s -fmodules-ts -DEXPLICIT_FLAG -fmodule-file=%t/explicit.pcm -Werror=padded
+
+import diag_flags;
+
+// Diagnostic flags from the module user make no difference to diagnostics
+// emitted within the module when using an explicitly-loaded module.
+#ifdef IMPLICIT_FLAG
+// expected-error@diag_flags.h:14 {{padding struct}}
+#elif defined(EXPLICIT_FLAG)
+// expected-warning@diag_flags.h:14 {{padding struct}}
+#else
+// expected-no-diagnostics
+#endif
+unsigned n = sizeof(Padded);