diff options
author | Sean Silva <chisophugis@gmail.com> | 2015-08-17 16:39:30 +0000 |
---|---|---|
committer | Sean Silva <chisophugis@gmail.com> | 2015-08-17 16:39:30 +0000 |
commit | 8b7c0398b6a30d40de29e6f982a766c5016fc544 (patch) | |
tree | 7e3b23283141c20fde6118681aebe3fe4a8e85eb /clang/lib/Lex/PPDirectives.cpp | |
parent | 06044f97d21dfdabe4f9599447005b08e13344c1 (diff) | |
download | bcm5719-llvm-8b7c0398b6a30d40de29e6f982a766c5016fc544.tar.gz bcm5719-llvm-8b7c0398b6a30d40de29e6f982a766c5016fc544.zip |
[modules] PR20507: Avoid silent textual inclusion.
Summary:
If a module was unavailable (either a missing requirement on the module
being imported, or a missing file anywhere in the top-level module (and
not dominated by an unsatisfied `requires`)), we would silently treat
inclusions as textual. This would cause all manner of crazy and
confusing errors (and would also silently "work" sometimes, making the
problem difficult to track down).
I'm really not a fan of the `M->isAvailable(getLangOpts(), getTargetInfo(),
Requirement, MissingHeader)` function; it seems to do too many things at
once, but for now I've done things in a sort of awkward way.
The changes to test/Modules/Inputs/declare-use/module.map
were necessitated because the thing that was meant to be tested there
(introduced in r197805) was predicated on silently falling back to textual
inclusion, which we no longer do.
The changes to test/Modules/Inputs/macro-reexport/module.modulemap
are just an overlooked missing header that seems to have been missing since
this code was committed (r213922), which is now caught.
Reviewers: rsmith, benlangmuir, djasper
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D10423
llvm-svn: 245228
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index ce64538de41..82f94d7da4e 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1674,6 +1674,29 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, getLangOpts().CurrentModule && SuggestedModule.getModule()->getTopLevelModuleName() != getLangOpts().ImplementationOfModule) { + + // If this include corresponds to a module but that module is + // unavailable, diagnose the situation and bail out. + if (!SuggestedModule.getModule()->isAvailable()) { + clang::Module::Requirement Requirement; + clang::Module::UnresolvedHeaderDirective MissingHeader; + Module *M = SuggestedModule.getModule(); + // Identify the cause. + (void)M->isAvailable(getLangOpts(), getTargetInfo(), Requirement, + MissingHeader); + if (MissingHeader.FileNameLoc.isValid()) { + Diag(MissingHeader.FileNameLoc, diag::err_module_header_missing) + << MissingHeader.IsUmbrella << MissingHeader.FileName; + } else { + Diag(M->DefinitionLoc, diag::err_module_unavailable) + << M->getFullModuleName() << Requirement.second << Requirement.first; + } + Diag(FilenameTok.getLocation(), + diag::note_implicit_top_level_module_import_here) + << M->getTopLevelModuleName(); + return; + } + // Compute the module access path corresponding to this module. // FIXME: Should we have a second loadModule() overload to avoid this // extra lookup step? |