@@ -108,13 +108,9 @@ CodeGenFunction::CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits Align,
108108 return RawAddress (Alloca, Ty, Align, KnownNonNull);
109109}
110110
111- RawAddress CodeGenFunction::CreateTempAlloca (llvm::Type *Ty, LangAS DestLangAS,
112- CharUnits Align, const Twine &Name,
113- llvm::Value *ArraySize,
114- RawAddress *AllocaAddr) {
115- RawAddress Alloca = CreateTempAllocaWithoutCast (Ty, Align, Name, ArraySize);
116- if (AllocaAddr)
117- *AllocaAddr = Alloca;
111+ RawAddress CodeGenFunction::MaybeCastAllocaAddressSpace (
112+ RawAddress Alloca, LangAS DestLangAS, llvm::Value *ArraySize) {
113+
118114 llvm::Value *V = Alloca.getPointer ();
119115 // Alloca always returns a pointer in alloca address space, which may
120116 // be different from the type defined by the language. For example,
@@ -134,7 +130,18 @@ RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, LangAS DestLangAS,
134130 /* IsNonNull=*/ true );
135131 }
136132
137- return RawAddress (V, Ty, Align, KnownNonNull);
133+ return RawAddress (V, Alloca.getElementType (), Alloca.getAlignment (),
134+ KnownNonNull);
135+ }
136+
137+ RawAddress CodeGenFunction::CreateTempAlloca (llvm::Type *Ty, LangAS DestLangAS,
138+ CharUnits Align, const Twine &Name,
139+ llvm::Value *ArraySize,
140+ RawAddress *AllocaAddr) {
141+ RawAddress Alloca = CreateTempAllocaWithoutCast (Ty, Align, Name, ArraySize);
142+ if (AllocaAddr)
143+ *AllocaAddr = Alloca;
144+ return MaybeCastAllocaAddressSpace (Alloca, DestLangAS, ArraySize);
138145}
139146
140147// / CreateTempAlloca - This creates an alloca and inserts it into the entry
@@ -2209,18 +2216,6 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr,
22092216 }
22102217 }
22112218
2212- // When storing a pointer, perform address space cast if needed.
2213- if (auto *ValueTy = dyn_cast<llvm::PointerType>(Value->getType ())) {
2214- if (auto *MemTy = dyn_cast<llvm::PointerType>(Addr.getElementType ())) {
2215- LangAS ValueAS = getLangASFromTargetAS (ValueTy->getAddressSpace ());
2216- LangAS MemAS = getLangASFromTargetAS (MemTy->getAddressSpace ());
2217- if (ValueAS != MemAS) {
2218- Value =
2219- getTargetHooks ().performAddrSpaceCast (*this , Value, ValueAS, MemTy);
2220- }
2221- }
2222- }
2223-
22242219 Value = EmitToMemory (Value, Ty);
22252220
22262221 LValue AtomicLValue =
0 commit comments