Skip to content

Commit c0fa16e

Browse files
Merge pull request #68000 from nate-chandler/cherrypick/main/rdar114013709
[IRGen] Cast fixed-size opaque globals.
2 parents 74a5a5e + 9981a82 commit c0fa16e

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

lib/IRGen/IRGenSIL.cpp

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

2997+
// Get the address of the type in context.
2998+
auto getAddressInContext = [this, &var](auto addr) -> Address {
2999+
SILType loweredTyInContext =
3000+
var->getLoweredTypeInContext(getExpansionContext());
3001+
auto &tiInContext = getTypeInfo(loweredTyInContext);
3002+
auto ptr = Builder.CreateBitOrPointerCast(
3003+
addr.getAddress(), tiInContext.getStorageType()->getPointerTo());
3004+
addr = Address(ptr, tiInContext.getStorageType(),
3005+
tiInContext.getBestKnownAlignment());
3006+
return addr;
3007+
};
3008+
29973009
// If the global is fixed-size in all resilience domains that can see it,
29983010
// we allocated storage for it statically, and there's nothing to do.
29993011
if (ti.isFixedSize(expansion)) {
3012+
addr = getAddressInContext(addr);
30003013
setLoweredAddress(i, addr);
30013014
return;
30023015
}
30033016

30043017
// Otherwise, the static storage for the global consists of a fixed-size
30053018
// buffer; project it.
30063019
addr = emitProjectValueInBuffer(*this, loweredTy, addr);
3007-
3008-
3009-
// Get the address of the type in context.
3010-
SILType loweredTyInContext = var->getLoweredTypeInContext(getExpansionContext());
3011-
auto &tiInContext = getTypeInfo(loweredTyInContext);
3012-
auto ptr = Builder.CreateBitOrPointerCast(addr.getAddress(),
3013-
tiInContext.getStorageType()->getPointerTo());
3014-
addr = Address(ptr, tiInContext.getStorageType(),
3015-
tiInContext.getBestKnownAlignment());
3020+
addr = getAddressInContext(addr);
30163021
setLoweredAddress(i, addr);
30173022
}
30183023

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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 ptr %{{[0-9]+}}, ptr @"$s13rdar1140137091xQrvp"
5+
actor Actor {}
6+
let x: some Actor = Actor()
7+

0 commit comments

Comments
 (0)