@@ -2958,25 +2958,30 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) {
2958
2958
Address addr = IGM.getAddrOfSILGlobalVariable (var, ti,
2959
2959
NotForDefinition);
2960
2960
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
+
2961
2973
// If the global is fixed-size in all resilience domains that can see it,
2962
2974
// we allocated storage for it statically, and there's nothing to do.
2963
2975
if (ti.isFixedSize (expansion)) {
2976
+ addr = getAddressInContext (addr);
2964
2977
setLoweredAddress (i, addr);
2965
2978
return ;
2966
2979
}
2967
2980
2968
2981
// Otherwise, the static storage for the global consists of a fixed-size
2969
2982
// buffer; project it.
2970
2983
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);
2980
2985
setLoweredAddress (i, addr);
2981
2986
}
2982
2987
0 commit comments