Skip to content

Commit 1a48e2d

Browse files
Merge pull request #67997 from nate-chandler/rdar114013709
5.9: [IRGen] Cast fixed-size opaque globals.
2 parents ebed23d + 9372173 commit 1a48e2d

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,25 +2958,30 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) {
29582958
Address addr = IGM.getAddrOfSILGlobalVariable(var, ti,
29592959
NotForDefinition);
29602960

2961+
// Get the address of the type in context.
2962+
auto getAddressInContext = [this, &var](auto addr) -> Address {
2963+
SILType loweredTyInContext =
2964+
var->getLoweredTypeInContext(getExpansionContext());
2965+
auto &tiInContext = getTypeInfo(loweredTyInContext);
2966+
auto ptr = Builder.CreateBitOrPointerCast(
2967+
addr.getAddress(), tiInContext.getStorageType()->getPointerTo());
2968+
addr = Address(ptr, tiInContext.getStorageType(),
2969+
tiInContext.getBestKnownAlignment());
2970+
return addr;
2971+
};
2972+
29612973
// If the global is fixed-size in all resilience domains that can see it,
29622974
// we allocated storage for it statically, and there's nothing to do.
29632975
if (ti.isFixedSize(expansion)) {
2976+
addr = getAddressInContext(addr);
29642977
setLoweredAddress(i, addr);
29652978
return;
29662979
}
29672980

29682981
// Otherwise, the static storage for the global consists of a fixed-size
29692982
// buffer; project it.
29702983
addr = emitProjectValueInBuffer(*this, loweredTy, addr);
2971-
2972-
2973-
// Get the address of the type in context.
2974-
SILType loweredTyInContext = var->getLoweredTypeInContext(getExpansionContext());
2975-
auto &tiInContext = getTypeInfo(loweredTyInContext);
2976-
auto ptr = Builder.CreateBitOrPointerCast(addr.getAddress(),
2977-
tiInContext.getStorageType()->getPointerTo());
2978-
addr = Address(ptr, tiInContext.getStorageType(),
2979-
tiInContext.getBestKnownAlignment());
2984+
addr = getAddressInContext(addr);
29802985
setLoweredAddress(i, addr);
29812986
}
29822987

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-frontend -O -primary-file %s -disable-availability-checking -emit-ir | %FileCheck %s
2+
3+
// CHECK: define{{( dllexport)?}}{{( protected)?}} i32 @main{{.*}} {
4+
// CHECK: store %swift.refcounted* %{{[0-9]+}},
5+
// CHECK-SAME: %swift.refcounted**
6+
// CHECK-SAME: bitcast (
7+
// CHECK-SAME: %T13rdar1140137095ActorC** @"$s13rdar1140137091xQrvp"
8+
// CHECK-SAME: to %swift.refcounted**)
9+
actor Actor {}
10+
let x: some Actor = Actor()
11+

0 commit comments

Comments
 (0)