Skip to content

Commit 3eb9ad4

Browse files
authored
Merge pull request #75323 from hborla/disable-symbol-linkage
2 parents e836e2c + 5e4277a commit 3eb9ad4

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,10 +1606,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
16061606
Opts.DisableDynamicActorIsolation |=
16071607
Args.hasArg(OPT_disable_dynamic_actor_isolation);
16081608

1609-
// @DebugDescription uses @_section and @_used attributes.
1610-
if (Opts.hasFeature(Feature::DebugDescriptionMacro))
1611-
Opts.enableFeature(Feature::SymbolLinkageMarkers);
1612-
16131609
#if SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
16141610
/// Enable round trip parsing via the new swift parser unless it is disabled
16151611
/// explicitly. The new Swift parser can have mismatches with C++ parser -

lib/Sema/TypeCheckAttr.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,8 +2376,36 @@ void AttributeChecker::visitExternAttr(ExternAttr *attr) {
23762376
}
23772377
}
23782378

2379+
static bool allowSymbolLinkageMarkers(ASTContext &ctx, Decl *D) {
2380+
if (ctx.LangOpts.hasFeature(Feature::SymbolLinkageMarkers))
2381+
return true;
2382+
2383+
auto *sourceFile = D->getDeclContext()->getParentModule()
2384+
->getSourceFileContainingLocation(D->getStartLoc());
2385+
if (!sourceFile)
2386+
return false;
2387+
2388+
auto expansion = sourceFile->getMacroExpansion();
2389+
auto *macroAttr = sourceFile->getAttachedMacroAttribute();
2390+
if (!expansion || !macroAttr)
2391+
return false;
2392+
2393+
auto *decl = expansion.dyn_cast<Decl *>();
2394+
if (!decl)
2395+
return false;
2396+
2397+
auto *macroDecl = decl->getResolvedMacro(macroAttr);
2398+
if (!macroDecl)
2399+
return false;
2400+
2401+
if (macroDecl->getParentModule()->isStdlibModule() &&
2402+
macroDecl->getName().getBaseIdentifier()
2403+
.str().equals("_DebugDescriptionProperty"))
2404+
return true;
2405+
}
2406+
23792407
void AttributeChecker::visitUsedAttr(UsedAttr *attr) {
2380-
if (!Ctx.LangOpts.hasFeature(Feature::SymbolLinkageMarkers)) {
2408+
if (!allowSymbolLinkageMarkers(Ctx, D)) {
23812409
diagnoseAndRemoveAttr(attr, diag::section_linkage_markers_disabled);
23822410
return;
23832411
}
@@ -2403,7 +2431,7 @@ void AttributeChecker::visitUsedAttr(UsedAttr *attr) {
24032431
}
24042432

24052433
void AttributeChecker::visitSectionAttr(SectionAttr *attr) {
2406-
if (!Ctx.LangOpts.hasFeature(Feature::SymbolLinkageMarkers)) {
2434+
if (!allowSymbolLinkageMarkers(Ctx, D)) {
24072435
diagnoseAndRemoveAttr(attr, diag::section_linkage_markers_disabled);
24082436
return;
24092437
}

0 commit comments

Comments
 (0)