Index: lib/CodeGen/CGBuiltin.cpp =================================================================== --- lib/CodeGen/CGBuiltin.cpp +++ lib/CodeGen/CGBuiltin.cpp @@ -1190,7 +1190,8 @@ CGM.getContext() .toCharUnitsFromBits(TI.getSuitableAlign()) .getQuantity(); - AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size); + AllocaInst *AI = Builder.CreateAlloca(CGM.getDataLayout(), + Builder.getInt8Ty(), Size); AI->setAlignment(SuitableAlignmentInBytes); return RValue::get(AI); } @@ -1202,7 +1203,8 @@ unsigned AlignmentInBits = AlignmentInBitsCI->getZExtValue(); unsigned AlignmentInBytes = CGM.getContext().toCharUnitsFromBits(AlignmentInBits).getQuantity(); - AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size); + AllocaInst *AI = Builder.CreateAlloca(CGM.getDataLayout(), + Builder.getInt8Ty(), Size); AI->setAlignment(AlignmentInBytes); return RValue::get(AI); } Index: lib/CodeGen/CGCall.cpp =================================================================== --- lib/CodeGen/CGCall.cpp +++ lib/CodeGen/CGCall.cpp @@ -1077,8 +1077,9 @@ /// Create a temporary allocation for the purposes of coercion. static Address CreateTempAllocaForCoercion(CodeGenFunction &CGF, llvm::Type *Ty, CharUnits MinAlign) { + const llvm::DataLayout &DL = CGF.CGM.getDataLayout(); // Don't use an alignment that's worse than what LLVM would prefer. - auto PrefAlign = CGF.CGM.getDataLayout().getPrefTypeAlignment(Ty); + auto PrefAlign = DL.getPrefTypeAlignment(Ty); CharUnits Align = std::max(MinAlign, CharUnits::fromQuantity(PrefAlign)); return CGF.CreateTempAlloca(Ty, Align); @@ -1101,10 +1102,10 @@ // first element is the same size as the whole struct, we can enter it. The // comparison must be made on the store size and not the alloca size. Using // the alloca size may overstate the size of the load. - uint64_t FirstEltSize = - CGF.CGM.getDataLayout().getTypeStoreSize(FirstElt); + const llvm::DataLayout &DL = CGF.CGM.getDataLayout(); + uint64_t FirstEltSize = DL.getTypeStoreSize(FirstElt); if (FirstEltSize < DstSize && - FirstEltSize < CGF.CGM.getDataLayout().getTypeStoreSize(SrcSTy)) + FirstEltSize < DL.getTypeStoreSize(SrcSTy)) return SrcPtr; // GEP into the first element. @@ -3713,12 +3714,13 @@ Address ArgMemory = Address::invalid(); const llvm::StructLayout *ArgMemoryLayout = nullptr; if (llvm::StructType *ArgStruct = CallInfo.getArgStruct()) { - ArgMemoryLayout = CGM.getDataLayout().getStructLayout(ArgStruct); + const llvm::DataLayout &DL = CGM.getDataLayout(); + ArgMemoryLayout = DL.getStructLayout(ArgStruct); llvm::Instruction *IP = CallArgs.getStackBase(); llvm::AllocaInst *AI; if (IP) { IP = IP->getNextNode(); - AI = new llvm::AllocaInst(ArgStruct, "argmem", IP); + AI = new llvm::AllocaInst(ArgStruct, DL.getStackAddrSpace(), "argmem", IP); } else { AI = CreateTempAlloca(ArgStruct, "argmem"); } Index: lib/CodeGen/CGDecl.cpp =================================================================== --- lib/CodeGen/CGDecl.cpp +++ lib/CodeGen/CGDecl.cpp @@ -924,7 +924,7 @@ return nullptr; llvm::Value *SizeV = llvm::ConstantInt::get(Int64Ty, Size); - Addr = Builder.CreateBitCast(Addr, Int8PtrTy); + Addr = Builder.CreateBitCast(Addr, Int8AllocaPtrTy); llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {SizeV, Addr}); C->setDoesNotThrow(); @@ -932,7 +932,7 @@ } void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr) { - Addr = Builder.CreateBitCast(Addr, Int8PtrTy); + Addr = Builder.CreateBitCast(Addr, Int8AllocaPtrTy); llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Size, Addr}); C->setDoesNotThrow(); @@ -1096,7 +1096,8 @@ llvm::Type *llvmTy = ConvertTypeForMem(elementType); // Allocate memory for the array. - llvm::AllocaInst *vla = Builder.CreateAlloca(llvmTy, elementCount, "vla"); + llvm::AllocaInst *vla = Builder.CreateAlloca(CGM.getDataLayout(), + llvmTy, elementCount, "vla"); vla->setAlignment(alignment.getQuantity()); address = Address(vla, alignment); @@ -1727,18 +1728,16 @@ /// Lazily declare the @llvm.lifetime.start intrinsic. llvm::Constant *CodeGenModule::getLLVMLifetimeStartFn() { if (LifetimeStartFn) return LifetimeStartFn; - llvm::Type *PtrTy = llvm::PointerType::getInt8PtrTy(getLLVMContext()); LifetimeStartFn = llvm::Intrinsic::getDeclaration( - &getModule(), llvm::Intrinsic::lifetime_start, { PtrTy }); + &getModule(), llvm::Intrinsic::lifetime_start, { Int8AllocaPtrTy }); return LifetimeStartFn; } /// Lazily declare the @llvm.lifetime.end intrinsic. llvm::Constant *CodeGenModule::getLLVMLifetimeEndFn() { if (LifetimeEndFn) return LifetimeEndFn; - llvm::Type *PtrTy = llvm::PointerType::getInt8PtrTy(getLLVMContext()); LifetimeEndFn = llvm::Intrinsic::getDeclaration( - &getModule(), llvm::Intrinsic::lifetime_end, { PtrTy }); + &getModule(), llvm::Intrinsic::lifetime_end, { Int8AllocaPtrTy }); return LifetimeEndFn; } Index: lib/CodeGen/CGExpr.cpp =================================================================== --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -71,7 +71,8 @@ /// block. llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, const Twine &Name) { - return new llvm::AllocaInst(Ty, nullptr, Name, AllocaInsertPt); + return new llvm::AllocaInst(Ty, CGM.getDataLayout().getStackAddrSpace(), + nullptr, Name, AllocaInsertPt); } /// CreateDefaultAlignTempAlloca - This creates an alloca with the Index: lib/CodeGen/CGObjCGNU.cpp =================================================================== --- lib/CodeGen/CGObjCGNU.cpp +++ lib/CodeGen/CGObjCGNU.cpp @@ -1330,7 +1330,8 @@ Receiver->getType(), IdTy, nullptr); // FIXME: Is this really supposed to be a dynamic alloca? - Address ObjCSuper = Address(Builder.CreateAlloca(ObjCSuperTy), + Address ObjCSuper = Address(Builder.CreateAlloca(CGM.getDataLayout(), + ObjCSuperTy), CGF.getPointerAlign()); Builder.CreateStore(Receiver, Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -111,6 +111,7 @@ C.getTargetInfo().getMaxPointerWidth()); Int8PtrTy = Int8Ty->getPointerTo(0); Int8PtrPtrTy = Int8PtrTy->getPointerTo(0); + Int8AllocaPtrTy = Int8Ty->getPointerTo(M.getDataLayout().getStackAddrSpace()); RuntimeCC = getTargetCodeGenInfo().getABIInfo().getRuntimeCC(); BuiltinCC = getTargetCodeGenInfo().getABIInfo().getBuiltinCC(); Index: lib/CodeGen/CodeGenTypeCache.h =================================================================== --- lib/CodeGen/CodeGenTypeCache.h +++ lib/CodeGen/CodeGenTypeCache.h @@ -60,6 +60,12 @@ llvm::PointerType *Int8PtrPtrTy; }; + /// void* in address space of allocas + union { + llvm::PointerType *VoidAllocaPtrTy; + llvm::PointerType *Int8AllocaPtrTy; + }; + /// The size and alignment of the builtin C type 'int'. This comes /// up enough in various ABI lowering tasks to be worth pre-computing. union {