Skip to content

Commit 9981a82

Browse files
committed
[IRGen] Cast fixed-size opaque globals.
In #66560 , a bug in the lowering of `global_addr` was fixed. Part of that fix was to postpone mapping the type of the global into context until getting the address of the global and projecting the buffer for the out-of-line value; at that point, the type is mapped into context and the address is cast. It introduced an issue for fixed-size globals, however: the type of such globals was not mapped into context; the result was that the lowered value set for the corresponding SIL value would have the wrong type. Fix that by extracting the code which mapped the type into context and cast the address to the appropriate lowered type into a lambda and call that lambda both in both the fixed-size (newly) and non-fixed-size (as before) cases. rdar://114013709
1 parent 9179bc5 commit 9981a82

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
@@ -2983,25 +2983,30 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) {
29832983
Address addr = IGM.getAddrOfSILGlobalVariable(var, ti,
29842984
NotForDefinition);
29852985

2986+
// Get the address of the type in context.
2987+
auto getAddressInContext = [this, &var](auto addr) -> Address {
2988+
SILType loweredTyInContext =
2989+
var->getLoweredTypeInContext(getExpansionContext());
2990+
auto &tiInContext = getTypeInfo(loweredTyInContext);
2991+
auto ptr = Builder.CreateBitOrPointerCast(
2992+
addr.getAddress(), tiInContext.getStorageType()->getPointerTo());
2993+
addr = Address(ptr, tiInContext.getStorageType(),
2994+
tiInContext.getBestKnownAlignment());
2995+
return addr;
2996+
};
2997+
29862998
// If the global is fixed-size in all resilience domains that can see it,
29872999
// we allocated storage for it statically, and there's nothing to do.
29883000
if (ti.isFixedSize(expansion)) {
3001+
addr = getAddressInContext(addr);
29893002
setLoweredAddress(i, addr);
29903003
return;
29913004
}
29923005

29933006
// Otherwise, the static storage for the global consists of a fixed-size
29943007
// buffer; project it.
29953008
addr = emitProjectValueInBuffer(*this, loweredTy, addr);
2996-
2997-
2998-
// Get the address of the type in context.
2999-
SILType loweredTyInContext = var->getLoweredTypeInContext(getExpansionContext());
3000-
auto &tiInContext = getTypeInfo(loweredTyInContext);
3001-
auto ptr = Builder.CreateBitOrPointerCast(addr.getAddress(),
3002-
tiInContext.getStorageType()->getPointerTo());
3003-
addr = Address(ptr, tiInContext.getStorageType(),
3004-
tiInContext.getBestKnownAlignment());
3009+
addr = getAddressInContext(addr);
30053010
setLoweredAddress(i, addr);
30063011
}
30073012

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)