Fix initial diagnostic state setup for an explicit module with no diagnostic pragmas.

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.

llvm-svn: 301846
This commit is contained in:
Richard Smith 2017-05-01 22:10:47 +00:00
parent 60cff50b27
commit ea74148f9f
3 changed files with 40 additions and 4 deletions

View 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.

View 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"
}

View File

@ -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);