@@ -2958,25 +2958,30 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) {
29582958 Address addr = IGM.getAddrOfSILGlobalVariable (var, ti,
29592959 NotForDefinition);
29602960
2961+ // Get the address of the type in context.
2962+ auto getAddressInContext = [this , &var](auto addr) -> Address {
2963+ SILType loweredTyInContext =
2964+ var->getLoweredTypeInContext (getExpansionContext ());
2965+ auto &tiInContext = getTypeInfo (loweredTyInContext);
2966+ auto ptr = Builder.CreateBitOrPointerCast (
2967+ addr.getAddress (), tiInContext.getStorageType ()->getPointerTo ());
2968+ addr = Address (ptr, tiInContext.getStorageType (),
2969+ tiInContext.getBestKnownAlignment ());
2970+ return addr;
2971+ };
2972+
29612973 // If the global is fixed-size in all resilience domains that can see it,
29622974 // we allocated storage for it statically, and there's nothing to do.
29632975 if (ti.isFixedSize (expansion)) {
2976+ addr = getAddressInContext (addr);
29642977 setLoweredAddress (i, addr);
29652978 return ;
29662979 }
29672980
29682981 // Otherwise, the static storage for the global consists of a fixed-size
29692982 // buffer; project it.
29702983 addr = emitProjectValueInBuffer (*this , loweredTy, addr);
2971-
2972-
2973- // Get the address of the type in context.
2974- SILType loweredTyInContext = var->getLoweredTypeInContext (getExpansionContext ());
2975- auto &tiInContext = getTypeInfo (loweredTyInContext);
2976- auto ptr = Builder.CreateBitOrPointerCast (addr.getAddress (),
2977- tiInContext.getStorageType ()->getPointerTo ());
2978- addr = Address (ptr, tiInContext.getStorageType (),
2979- tiInContext.getBestKnownAlignment ());
2984+ addr = getAddressInContext (addr);
29802985 setLoweredAddress (i, addr);
29812986}
29822987
0 commit comments