@@ -4157,34 +4157,29 @@ visitMagicIdentifierLiteralExpr(MagicIdentifierLiteralExpr *E, SGFContext C) {
41574157 SILModule &M = SGF.SGM .M ;
41584158 SILBuilder &B = SGF.B ;
41594159
4160- StructInst *S = nullptr ;
4160+ GlobalAddrInst *ModuleBase = nullptr ;
4161+
41614162 if (M.getASTContext ().LangOpts .Target .isOSWindows ()) {
41624163 auto ImageBase = M.lookUpGlobalVariable (" __ImageBase" );
41634164 if (!ImageBase)
41644165 ImageBase =
41654166 SILGlobalVariable::create (M, SILLinkage::Public, IsNotSerialized,
41664167 " __ImageBase" , BuiltinRawPtrTy);
4167-
4168- auto ImageBaseAddr = B.createGlobalAddr (SILLoc, ImageBase);
4169- auto ImageBasePointer =
4170- B.createAddressToPointer (SILLoc, ImageBaseAddr, BuiltinRawPtrTy,
4171- /* needsStackProtection=*/ false );
4172- S = B.createStruct (SILLoc, UnsafeRawPtrTy, { ImageBasePointer });
4168+ ModuleBase = B.createGlobalAddr (SILLoc, ImageBase);
41734169 } else {
4174- auto DSOGlobal = M.lookUpGlobalVariable (" __dso_handle" );
4175- if (!DSOGlobal)
4176- DSOGlobal =
4177- SILGlobalVariable::create (M, SILLinkage::PublicExternal,
4178- IsNotSerialized, " __dso_handle" ,
4179- BuiltinRawPtrTy);
4180-
4181- auto DSOAddr = B.createGlobalAddr (SILLoc, DSOGlobal);
4182- auto DSOPointer =
4183- B.createAddressToPointer (SILLoc, DSOAddr, BuiltinRawPtrTy,
4184- /* needsStackProtection=*/ false );
4185- S = B.createStruct (SILLoc, UnsafeRawPtrTy, { DSOPointer });
4170+ auto DSOHandle = M.lookUpGlobalVariable (" __dso_handle" );
4171+ if (!DSOHandle)
4172+ DSOHandle = SILGlobalVariable::create (M, SILLinkage::PublicExternal,
4173+ IsNotSerialized, " __dso_handle" ,
4174+ BuiltinRawPtrTy);
4175+ ModuleBase = B.createGlobalAddr (SILLoc, DSOHandle);
41864176 }
41874177
4178+ auto ModuleBasePointer =
4179+ B.createAddressToPointer (SILLoc, ModuleBase, BuiltinRawPtrTy,
4180+ /* needsStackProtection=*/ false );
4181+ StructInst *S =
4182+ B.createStruct (SILLoc, UnsafeRawPtrTy, { ModuleBasePointer });
41884183 return RValue (SGF, E, ManagedValue::forUnmanaged (S));
41894184 }
41904185 }
0 commit comments