diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index 6bec19b3d5c77..c2386847a4253 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -2983,9 +2983,22 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) { Address addr = IGM.getAddrOfSILGlobalVariable(var, ti, NotForDefinition); + // Get the address of the type in context. + auto getAddressInContext = [this, &var](auto addr) -> Address { + SILType loweredTyInContext = + var->getLoweredTypeInContext(getExpansionContext()); + auto &tiInContext = getTypeInfo(loweredTyInContext); + auto ptr = Builder.CreateBitOrPointerCast( + addr.getAddress(), tiInContext.getStorageType()->getPointerTo()); + addr = Address(ptr, tiInContext.getStorageType(), + tiInContext.getBestKnownAlignment()); + return addr; + }; + // If the global is fixed-size in all resilience domains that can see it, // we allocated storage for it statically, and there's nothing to do. if (ti.isFixedSize(expansion)) { + addr = getAddressInContext(addr); setLoweredAddress(i, addr); return; } @@ -2993,15 +3006,7 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) { // Otherwise, the static storage for the global consists of a fixed-size // buffer; project it. addr = emitProjectValueInBuffer(*this, loweredTy, addr); - - - // Get the address of the type in context. - SILType loweredTyInContext = var->getLoweredTypeInContext(getExpansionContext()); - auto &tiInContext = getTypeInfo(loweredTyInContext); - auto ptr = Builder.CreateBitOrPointerCast(addr.getAddress(), - tiInContext.getStorageType()->getPointerTo()); - addr = Address(ptr, tiInContext.getStorageType(), - tiInContext.getBestKnownAlignment()); + addr = getAddressInContext(addr); setLoweredAddress(i, addr); } diff --git a/validation-test/IRGen/rdar114013709.swift b/validation-test/IRGen/rdar114013709.swift new file mode 100644 index 0000000000000..71b1549c0d508 --- /dev/null +++ b/validation-test/IRGen/rdar114013709.swift @@ -0,0 +1,7 @@ +// RUN: %target-swift-frontend -O -primary-file %s -disable-availability-checking -emit-ir | %FileCheck %s + +// CHECK: define{{( dllexport)?}}{{( protected)?}} i32 @main{{.*}} { +// CHECK: store ptr %{{[0-9]+}}, ptr @"$s13rdar1140137091xQrvp" +actor Actor {} +let x: some Actor = Actor() +