Skip to content

Commit 1f8e88d

Browse files
authored
Merge pull request #85908 from drexin/wip-163631865
[IRGen] Use proper linkage for async function pointers to partial app…
2 parents 560eb9d + 0fdca11 commit 1f8e88d

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

include/swift/IRGen/Linking.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,15 @@ class LinkEntity {
18631863

18641864
bool isAlwaysSharedLinkage() const;
18651865

1866+
/// Partial apply forwarders always need real private linkage,
1867+
/// to ensure the correct implementation is used in case of
1868+
/// colliding symbols.
1869+
bool privateMeansPrivate() const {
1870+
return getKind() == Kind::PartialApplyForwarder ||
1871+
getKind() == Kind::PartialApplyForwarderAsyncFunctionPointer ||
1872+
getKind() == Kind::PartialApplyForwarderCoroFunctionPointer;
1873+
}
1874+
18661875
/// Whether the link entity's definitions must be considered non-unique.
18671876
///
18681877
/// This applies only in the Embedded Swift linkage model, and is used for

lib/IRGen/GenDecl.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,11 +2326,11 @@ void IRGenerator::emitEntryPointInfo() {
23262326
IGM.addUsedGlobal(var);
23272327
}
23282328

2329-
static IRLinkage
2330-
getIRLinkage(StringRef name, const UniversalLinkageInfo &info,
2331-
SILLinkage linkage, ForDefinition_t isDefinition,
2332-
bool isWeakImported, bool isKnownLocal,
2333-
bool hasNonUniqueDefinition) {
2329+
static IRLinkage getIRLinkage(StringRef name, const UniversalLinkageInfo &info,
2330+
SILLinkage linkage, ForDefinition_t isDefinition,
2331+
bool isWeakImported, bool isKnownLocal,
2332+
bool hasNonUniqueDefinition,
2333+
bool privateMeansPrivate) {
23342334
#define RESULT(LINKAGE, VISIBILITY, DLL_STORAGE) \
23352335
IRLinkage{llvm::GlobalValue::LINKAGE##Linkage, \
23362336
llvm::GlobalValue::VISIBILITY##Visibility, \
@@ -2392,12 +2392,15 @@ getIRLinkage(StringRef name, const UniversalLinkageInfo &info,
23922392
case SILLinkage::Private: {
23932393
if (info.forcePublicDecls() && !isDefinition)
23942394
return getIRLinkage(name, info, SILLinkage::PublicExternal, isDefinition,
2395-
isWeakImported, isKnownLocal, hasNonUniqueDefinition);
2396-
2397-
auto linkage = info.needLinkerToMergeDuplicateSymbols()
2398-
? llvm::GlobalValue::LinkOnceODRLinkage
2399-
: llvm::GlobalValue::InternalLinkage;
2400-
auto visibility = info.shouldAllPrivateDeclsBeVisibleFromOtherFiles()
2395+
isWeakImported, isKnownLocal, hasNonUniqueDefinition,
2396+
privateMeansPrivate);
2397+
2398+
auto linkage =
2399+
info.needLinkerToMergeDuplicateSymbols() && !privateMeansPrivate
2400+
? llvm::GlobalValue::LinkOnceODRLinkage
2401+
: llvm::GlobalValue::InternalLinkage;
2402+
auto visibility = info.shouldAllPrivateDeclsBeVisibleFromOtherFiles() &&
2403+
!privateMeansPrivate
24012404
? llvm::GlobalValue::HiddenVisibility
24022405
: llvm::GlobalValue::DefaultVisibility;
24032406
return {linkage, visibility, llvm::GlobalValue::DefaultStorageClass};
@@ -2448,8 +2451,8 @@ void irgen::updateLinkageForDefinition(IRGenModule &IGM,
24482451
auto IRL =
24492452
getIRLinkage(global->hasName() ? global->getName() : StringRef(),
24502453
linkInfo, entity.getLinkage(ForDefinition), ForDefinition,
2451-
weakImported, isKnownLocal,
2452-
entity.hasNonUniqueDefinition());
2454+
weakImported, isKnownLocal, entity.hasNonUniqueDefinition(),
2455+
entity.privateMeansPrivate());
24532456
ApplyIRLinkage(IRL).to(global);
24542457

24552458
LinkInfo link = LinkInfo::get(IGM, entity, ForDefinition);
@@ -2500,10 +2503,10 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo,
25002503
}
25012504

25022505
bool weakImported = entity.isWeakImported(swiftModule);
2503-
result.IRL = getIRLinkage(result.Name, linkInfo,
2504-
entity.getLinkage(isDefinition), isDefinition,
2505-
weakImported, isKnownLocal,
2506-
entity.hasNonUniqueDefinition());
2506+
result.IRL = getIRLinkage(
2507+
result.Name, linkInfo, entity.getLinkage(isDefinition), isDefinition,
2508+
weakImported, isKnownLocal, entity.hasNonUniqueDefinition(),
2509+
entity.privateMeansPrivate());
25072510
result.ForDefinition = isDefinition;
25082511
return result;
25092512
}
@@ -2515,7 +2518,8 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo, StringRef name,
25152518
result.Name += name;
25162519
result.IRL = getIRLinkage(name, linkInfo, linkage, isDefinition,
25172520
isWeakImported, linkInfo.Internalize,
2518-
/*hasNonUniqueDefinition=*/false);
2521+
/*hasNonUniqueDefinition=*/false,
2522+
/*privateMeansPrivate=*/false);
25192523
result.ForDefinition = isDefinition;
25202524
return result;
25212525
}

test/IRGen/async/partial_apply_forwarder.sil

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ entry(%e : $EmptyType, %b : $WeakBox<τ_0_0>):
8989
unreachable
9090
}
9191

92+
// CHECK-DAG: @"$s7takingQTATu" = internal
93+
// CHECK-DAG: @"$s11takingQAndSTATu" = internal
94+
// CHECK-DAG: @"$s13inner_closureTATu" = internal
95+
// CHECK-DAG: @"$s15returns_closureTATu" = internal
96+
9297
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @bind_polymorphic_param_from_context(
9398
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s7takingQTA"(
9499
sil public @bind_polymorphic_param_from_context : $@async @convention(thin) <τ_0_1>(@in τ_0_1) -> @owned @async @callee_guaranteed () -> () {

0 commit comments

Comments
 (0)