Skip to content

Commit 42e1685

Browse files
committed
Revert "Revert the error check for link decls in submodules as that is a feature as indicated by the test case clang/test/Modules/autolink.m"
This reverts commit 3286622.
1 parent 3286622 commit 42e1685

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,8 @@ def err_mmap_expected_feature : Error<"expected a feature name">;
911911
def err_mmap_expected_attribute : Error<"expected an attribute name">;
912912
def err_mmap_link_redecalration : Error<"redeclaration of link library '%0'">;
913913
def note_mmap_prev_link_declaration : Note<"previously declared here">;
914+
def err_mmap_submodule_link_decl
915+
: Error<"link declaration is not allowed in submodules">;
914916
def warn_mmap_unknown_attribute : Warning<"unknown attribute '%0'">,
915917
InGroup<IgnoredAttributes>;
916918
def warn_mmap_mismatched_private_submodule : Warning<

clang/lib/Lex/ModuleMapFile.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,12 @@ std::optional<LinkDecl> ModuleMapFileParser::parseLinkDecl(
853853

854854
// Make sure we eat all the tokens when we report the errors so parsing
855855
// can continue.
856+
if (!TopLevel) {
857+
Diags.Report(LD.Location, diag::err_mmap_submodule_link_decl);
858+
HadError = true;
859+
return std::nullopt;
860+
}
861+
856862
auto [It, Inserted] =
857863
SeenLinkDecl.insert(std::make_pair(Library, LD.Location));
858864
if (!Inserted) {

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module A {
88

99
module B {
1010
header "B.h"
11-
link "libraryA"
11+
link "libraryB"
1212
}
1313

1414
link "libraryA"
@@ -41,9 +41,7 @@ module C {
4141
// RUN: not clang-scan-deps -compilation-database %t/cdb.json -format \
4242
// RUN: experimental-full 2>&1 | FileCheck %s
4343

44-
// Note that the link declaration in submodule B does not conflict with the
45-
// first link declaration in module A, since we only check link declaration
46-
// duplications within the current module.
47-
// CHECK: module.modulemap:10:3: error: redeclaration of link library 'libraryA'
44+
// CHECK: module.modulemap:6:5: error: link decl is not allowed in submodules
45+
// CHECK-NEXT: module.modulemap:10:3: error: redeclaration of link library 'libraryA'
4846
// CHECK-NEXT: module.modulemap:9:3: note: previously declared here
49-
// CHECK-NOT: module.modulemap:15:3: error: redeclaration of link library 'libraryA'
47+
// CHECK-NOT: module.modulemap:15:3: error: redeclaration of link library 'libraryA'

0 commit comments

Comments
 (0)