@@ -2994,25 +2994,30 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) {
2994
2994
Address addr = IGM.getAddrOfSILGlobalVariable (var, ti,
2995
2995
NotForDefinition);
2996
2996
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
+
2997
3009
// If the global is fixed-size in all resilience domains that can see it,
2998
3010
// we allocated storage for it statically, and there's nothing to do.
2999
3011
if (ti.isFixedSize (expansion)) {
3012
+ addr = getAddressInContext (addr);
3000
3013
setLoweredAddress (i, addr);
3001
3014
return ;
3002
3015
}
3003
3016
3004
3017
// Otherwise, the static storage for the global consists of a fixed-size
3005
3018
// buffer; project it.
3006
3019
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);
3016
3021
setLoweredAddress (i, addr);
3017
3022
}
3018
3023
0 commit comments