@@ -119,7 +119,7 @@ struct ModuleMapFileParser {
119119 std::optional<UmbrellaDirDecl>
120120 parseUmbrellaDirDecl (SourceLocation UmbrellaLoc);
121121 std::optional<LinkDecl>
122- parseLinkDecl (llvm::StringMap<SourceLocation> &SeenLinkDecl, bool TopLevel );
122+ parseLinkDecl (llvm::StringMap<SourceLocation> &SeenLinkDecl, bool Allowed );
123123
124124 SourceLocation consumeToken ();
125125 void skipUntil (MMToken::TokenKind K);
@@ -407,7 +407,9 @@ std::optional<ModuleDecl> ModuleMapFileParser::parseModuleDecl(bool TopLevel) {
407407 break ;
408408
409409 case MMToken::LinkKeyword:
410- SubDecl = parseLinkDecl (SeenLinkDecl, TopLevel);
410+ // Link decls are only allowed in top level modules or explicit
411+ // submodules.
412+ SubDecl = parseLinkDecl (SeenLinkDecl, TopLevel || MDecl.Explicit );
411413 break ;
412414
413415 default :
@@ -825,7 +827,7 @@ ModuleMapFileParser::parseUmbrellaDirDecl(clang::SourceLocation UmbrellaLoc) {
825827// / module-declaration:
826828// / 'link' 'framework'[opt] string-literal
827829std::optional<LinkDecl> ModuleMapFileParser::parseLinkDecl (
828- llvm::StringMap<SourceLocation> &SeenLinkDecl, bool TopLevel ) {
830+ llvm::StringMap<SourceLocation> &SeenLinkDecl, bool Allowed ) {
829831 assert (Tok.is (MMToken::LinkKeyword));
830832 LinkDecl LD;
831833 LD.Location = consumeToken ();
@@ -853,7 +855,7 @@ std::optional<LinkDecl> ModuleMapFileParser::parseLinkDecl(
853855
854856 // Make sure we eat all the tokens when we report the errors so parsing
855857 // can continue.
856- if (!TopLevel ) {
858+ if (!Allowed ) {
857859 Diags.Report (LD.Location , diag::err_mmap_submodule_link_decl);
858860 HadError = true ;
859861 return std::nullopt ;
0 commit comments