Skip to content

Commit 4b36ae5

Browse files
committed
Remove the check against link decls in submodules.
1 parent 54ec813 commit 4b36ae5

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -915,10 +915,6 @@ def err_mmap_expected_attribute : Error<"expected an attribute name">;
915915
def warn_mmap_link_redeclaration : Warning<"redeclaration of link library '%0'">,
916916
InGroup<DiagGroup<"module-link-redeclaration">>, DefaultError;
917917
def note_mmap_prev_link_declaration : Note<"previously declared here">;
918-
def warn_mmap_submodule_link_decl
919-
: Warning<"link declaration is not allowed in submodules">,
920-
InGroup<DiagGroup<"module-submodule-link-decl">>,
921-
DefaultError;
922918
def warn_mmap_unknown_attribute : Warning<"unknown attribute '%0'">,
923919
InGroup<IgnoredAttributes>;
924920
def warn_mmap_mismatched_private_submodule : Warning<

clang/lib/Lex/ModuleMapFile.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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 Allowed);
122+
parseLinkDecl(llvm::StringMap<SourceLocation> &SeenLinkDecl);
123123

124124
SourceLocation consumeToken();
125125
void skipUntil(MMToken::TokenKind K);
@@ -409,7 +409,7 @@ std::optional<ModuleDecl> ModuleMapFileParser::parseModuleDecl(bool TopLevel) {
409409
case MMToken::LinkKeyword:
410410
// Link decls are only allowed in top level modules or explicit
411411
// submodules.
412-
SubDecl = parseLinkDecl(SeenLinkDecl, TopLevel || MDecl.Explicit);
412+
SubDecl = parseLinkDecl(SeenLinkDecl);
413413
break;
414414

415415
default:
@@ -827,7 +827,7 @@ ModuleMapFileParser::parseUmbrellaDirDecl(clang::SourceLocation UmbrellaLoc) {
827827
/// module-declaration:
828828
/// 'link' 'framework'[opt] string-literal
829829
std::optional<LinkDecl> ModuleMapFileParser::parseLinkDecl(
830-
llvm::StringMap<SourceLocation> &SeenLinkDecl, bool Allowed) {
830+
llvm::StringMap<SourceLocation> &SeenLinkDecl) {
831831
assert(Tok.is(MMToken::LinkKeyword));
832832
LinkDecl LD;
833833
LD.Location = consumeToken();
@@ -853,12 +853,8 @@ std::optional<LinkDecl> ModuleMapFileParser::parseLinkDecl(
853853
LD.Library = Library;
854854
consumeToken();
855855

856-
// Make sure we eat all the tokens when we report the errors so parsing
856+
// Make sure we eat all the token when we report the errors so parsing
857857
// can continue.
858-
if (!Allowed) {
859-
Diags.Report(LD.Location, diag::warn_mmap_submodule_link_decl);
860-
}
861-
862858
auto [It, Inserted] =
863859
SeenLinkDecl.insert(std::make_pair(Library, LD.Location));
864860
if (!Inserted) {

clang/test/ClangScanDeps/link-libraries-diag-dup.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ module A {
1414
explicit module D {
1515
header "D.h"
1616
link "libraryD"
17+
link "libraryD"
1718
}
1819

20+
link "libraryB"
1921
link "libraryA"
2022
link "libraryA"
2123
}
@@ -49,9 +51,10 @@ module C {
4951
// RUN: not clang-scan-deps -compilation-database %t/cdb.json -format \
5052
// RUN: experimental-full 2>&1 | FileCheck %s
5153

52-
// Note that module D does not report an error because it is explicit.
53-
// Therefore we can use CHECK-NEXT for the redeclaration error on line 15.
54-
// CHECK: module.modulemap:6:5: error: link declaration is not allowed in submodules [-Wmodule-submodule-link-decl]
55-
// CHECK-NEXT: module.modulemap:15:3: error: redeclaration of link library 'libraryA' [-Wmodule-link-redeclaration]
56-
// CHECK-NEXT: module.modulemap:14:3: note: previously declared here
57-
// CHECK-NOT: module.modulemap:20:3: error: redeclaration of link library 'libraryA'
54+
// Note that the `link "libraryB"` in the top level module A does not
55+
// cause an issue because we only check within a module.
56+
// CHECK: 12:5: error: redeclaration of link library 'libraryD' [-Wmodule-link-redeclaration]
57+
// CHECK-NEXT: 11:5: note: previously declared here
58+
// CHECK-NEXT: 17:3: error: redeclaration of link library 'libraryA' [-Wmodule-link-redeclaration]
59+
// CHECK-NEXT: 16:3: note: previously declared here
60+
// CHECK-NOT: error: redeclaration of link library 'libraryB'

0 commit comments

Comments
 (0)