Skip to content

Commit 9da02e7

Browse files
authored
Revert "[clang][Modules] Reporting Errors for Duplicating Link Declar… (#157154)
…ations in `modulemap`s (#148959)" This reverts commit 538e9e8 for two reasons. 1. Link decls in submodules can make sense even if the submodule is not explicit. We need to review the error check. This PR reverts the check so we still allow link decls in submodules. 2. It is not a fatal error to have duplicating link decls. The linker deduplicates them anyways. rdar://159467837
1 parent cd8c3e5 commit 9da02e7

File tree

3 files changed

+4
-92
lines changed

3 files changed

+4
-92
lines changed

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -912,11 +912,6 @@ def err_mmap_nested_submodule_id : Error<
912912
"qualified module name can only be used to define modules at the top level">;
913913
def err_mmap_expected_feature : Error<"expected a feature name">;
914914
def err_mmap_expected_attribute : Error<"expected an attribute name">;
915-
def warn_mmap_link_redeclaration : Warning<"redeclaration of link library '%0'">,
916-
InGroup<DiagGroup<"module-link-redeclaration">>, DefaultError;
917-
def note_mmap_prev_link_declaration : Note<"previously declared here">;
918-
def err_mmap_submodule_link_decl
919-
: Error<"link declaration is not allowed in submodules">;
920915
def warn_mmap_unknown_attribute : Warning<"unknown attribute '%0'">,
921916
InGroup<IgnoredAttributes>;
922917
def warn_mmap_mismatched_private_submodule : Warning<

clang/lib/Lex/ModuleMapFile.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ struct ModuleMapFileParser {
118118
std::optional<ExcludeDecl> parseExcludeDecl(clang::SourceLocation LeadingLoc);
119119
std::optional<UmbrellaDirDecl>
120120
parseUmbrellaDirDecl(SourceLocation UmbrellaLoc);
121-
std::optional<LinkDecl>
122-
parseLinkDecl(llvm::StringMap<SourceLocation> &SeenLinkDecl, bool Allowed);
121+
std::optional<LinkDecl> parseLinkDecl();
123122

124123
SourceLocation consumeToken();
125124
void skipUntil(MMToken::TokenKind K);
@@ -326,7 +325,6 @@ std::optional<ModuleDecl> ModuleMapFileParser::parseModuleDecl(bool TopLevel) {
326325
SourceLocation LBraceLoc = consumeToken();
327326

328327
bool Done = false;
329-
llvm::StringMap<SourceLocation> SeenLinkDecl;
330328
do {
331329
std::optional<Decl> SubDecl;
332330
switch (Tok.Kind) {
@@ -407,9 +405,7 @@ std::optional<ModuleDecl> ModuleMapFileParser::parseModuleDecl(bool TopLevel) {
407405
break;
408406

409407
case MMToken::LinkKeyword:
410-
// Link decls are only allowed in top level modules or explicit
411-
// submodules.
412-
SubDecl = parseLinkDecl(SeenLinkDecl, TopLevel || MDecl.Explicit);
408+
SubDecl = parseLinkDecl();
413409
break;
414410

415411
default:
@@ -826,8 +822,7 @@ ModuleMapFileParser::parseUmbrellaDirDecl(clang::SourceLocation UmbrellaLoc) {
826822
///
827823
/// module-declaration:
828824
/// 'link' 'framework'[opt] string-literal
829-
std::optional<LinkDecl> ModuleMapFileParser::parseLinkDecl(
830-
llvm::StringMap<SourceLocation> &SeenLinkDecl, bool Allowed) {
825+
std::optional<LinkDecl> ModuleMapFileParser::parseLinkDecl() {
831826
assert(Tok.is(MMToken::LinkKeyword));
832827
LinkDecl LD;
833828
LD.Location = consumeToken();
@@ -843,33 +838,12 @@ std::optional<LinkDecl> ModuleMapFileParser::parseLinkDecl(
843838
if (!Tok.is(MMToken::StringLiteral)) {
844839
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_library_name)
845840
<< LD.Framework << SourceRange(LD.Location);
846-
consumeToken();
847841
HadError = true;
848842
return std::nullopt;
849843
}
850844

851-
StringRef Library = Tok.getString();
852-
853-
LD.Library = Library;
845+
LD.Library = Tok.getString();
854846
consumeToken();
855-
856-
// Make sure we eat all the tokens when we report the errors so parsing
857-
// can continue.
858-
if (!Allowed) {
859-
Diags.Report(LD.Location, diag::err_mmap_submodule_link_decl);
860-
HadError = true;
861-
return std::nullopt;
862-
}
863-
864-
auto [It, Inserted] =
865-
SeenLinkDecl.insert(std::make_pair(Library, LD.Location));
866-
if (!Inserted) {
867-
Diags.Report(LD.Location, diag::warn_mmap_link_redeclaration) << Library;
868-
Diags.Report(It->second, diag::note_mmap_prev_link_declaration);
869-
HadError = true;
870-
return std::nullopt;
871-
}
872-
873847
return std::move(LD);
874848
}
875849

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

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)