Skip to content

Commit fc86d09

Browse files
committed
IRGen: apply IR linkage to trivial property descriptors
This ensures that the trivial property descriptors is externally accessible on targets like Windows which does not export symbols by default. Thanks to Joe Groff for the pointer about the global aliases for trivial property descriptors!
1 parent be33d17 commit fc86d09

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/IRGen/GenKeyPath.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,14 +1269,18 @@ void IRGenModule::emitSILProperty(SILProperty *prop) {
12691269
var->setConstant(true);
12701270
var->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
12711271
var->setAlignment(4);
1272-
1272+
12731273
TheTrivialPropertyDescriptor = var;
12741274
} else {
12751275
auto entity = LinkEntity::forPropertyDescriptor(prop->getDecl());
12761276
auto linkInfo = LinkInfo::get(*this, entity, ForDefinition);
1277-
llvm::GlobalAlias::create(linkInfo.getLinkage(),
1278-
linkInfo.getName(),
1279-
TheTrivialPropertyDescriptor);
1277+
auto *GA = llvm::GlobalAlias::create(linkInfo.getLinkage(),
1278+
linkInfo.getName(),
1279+
TheTrivialPropertyDescriptor);
1280+
ApplyIRLinkage({linkInfo.getLinkage(),
1281+
linkInfo.getVisibility(),
1282+
llvm::GlobalValue::DLLExportStorageClass})
1283+
.to(GA);
12801284
}
12811285
return;
12821286
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %swift -target x86_64-unknown-windows-msvc -parse-stdlib -module-name Swift -enable-resilience -S -emit-ir -o - %s | %FileCheck %s
2+
3+
public struct S {}
4+
extension S {
5+
public var i: () { return () }
6+
public var j: () { return () }
7+
}
8+
9+
// CHECK: @"$ss1SV1jytvpMV" = dllexport alias { i32 }, { i32 }* @"$ss1SV1iytvpMV"
10+

0 commit comments

Comments
 (0)