diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-05-30 05:22:59 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-05-30 05:22:59 +0000 |
| commit | 51d09c512b9517578024f9aaf7587dd97965ef86 (patch) | |
| tree | d2cbf2fcc6fb4631c337a472675cbacb477ba949 | |
| parent | 08dfd5326997265e42f08c2ce97c53874f6f7f54 (diff) | |
| download | bcm5719-llvm-51d09c512b9517578024f9aaf7587dd97965ef86.tar.gz bcm5719-llvm-51d09c512b9517578024f9aaf7587dd97965ef86.zip | |
Diagnose attempts to build a preprocessed module that defines an unavailable submodule.
The errors we would otherwise get are incomprehensible, as we would enter the
module but not make its contents visible to itself.
llvm-svn: 304190
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticLexKinds.td | 2 | ||||
| -rw-r--r-- | clang/lib/Lex/Pragma.cpp | 18 | ||||
| -rw-r--r-- | clang/test/Modules/preprocess-unavailable.cpp | 12 |
3 files changed, 32 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index 77db8993f01..b393ce5f154 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -525,6 +525,8 @@ def err_pp_module_begin_without_module_end : Error< def err_pp_module_end_without_module_begin : Error< "no matching '#pragma clang module begin' for this " "'#pragma clang module end'">; +def note_pp_module_begin_here : Note< + "entering module '%0' due to this pragma">; def err_defined_macro_name : Error<"'defined' cannot be used as a macro name">; def err_paste_at_start : Error< diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 2d078a4e760..e1d981527be 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -1407,6 +1407,24 @@ struct PragmaModuleBeginHandler : public PragmaHandler { M = NewM; } + // If the module isn't available, it doesn't make sense to enter it. + if (!M->isAvailable()) { + Module::Requirement Requirement; + Module::UnresolvedHeaderDirective MissingHeader; + (void)M->isAvailable(PP.getLangOpts(), PP.getTargetInfo(), + Requirement, MissingHeader); + if (MissingHeader.FileNameLoc.isValid()) { + PP.Diag(MissingHeader.FileNameLoc, diag::err_module_header_missing) + << MissingHeader.IsUmbrella << MissingHeader.FileName; + } else { + PP.Diag(M->DefinitionLoc, diag::err_module_unavailable) + << M->getFullModuleName() << Requirement.second << Requirement.first; + } + PP.Diag(BeginLoc, diag::note_pp_module_begin_here) + << M->getTopLevelModuleName(); + return; + } + // Enter the scope of the submodule. PP.EnterSubmodule(M, BeginLoc, /*ForPragma*/true); PP.EnterAnnotationToken(SourceRange(BeginLoc, ModuleName.back().second), diff --git a/clang/test/Modules/preprocess-unavailable.cpp b/clang/test/Modules/preprocess-unavailable.cpp new file mode 100644 index 00000000000..e568cd7b525 --- /dev/null +++ b/clang/test/Modules/preprocess-unavailable.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -x c++-module-map %s -fmodule-name=a -verify +module a { + module b { + requires cplusplus11 + } +} +#pragma clang module contents +// expected-error@3 {{module 'a.b' requires feature 'cplusplus11'}} +#pragma clang module begin a.b // expected-note {{entering module 'a' due to this pragma}} +int f(); +int g() { f(); } +#pragma clang module end // expected-error {{no matching '#pragma clang module begin'}} |

