@@ -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
0 commit comments