From 21e7f5e24eb1fef1676d70eb013b1346482a7bac Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Fri, 9 Nov 2018 17:15:06 +0000 Subject: [PATCH] Use the correct address space when emitting the ctor function list This patch modifies clang so that, if compiling for a target that explicitly specifies a nonzero program memory address space, the constructor list global will have the same address space as the functions it contains. AVR is the only in-tree backend which has a nonzero program memory address space. Without this, the IR verifier would always fail if a constructor was used on a Harvard architecture backend. This has no functional change to any in-tree backends except AVR. llvm-svn: 346520 --- clang/lib/CodeGen/CodeGenModule.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index f55fa3f1bcb7..d62d8be195df 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1105,11 +1105,12 @@ void CodeGenModule::EmitCtorList(CtorList &Fns, const char *GlobalName) { // Ctor function type is void()*. llvm::FunctionType* CtorFTy = llvm::FunctionType::get(VoidTy, false); - llvm::Type *CtorPFTy = llvm::PointerType::getUnqual(CtorFTy); + llvm::Type *CtorPFTy = llvm::PointerType::get(CtorFTy, + TheModule.getDataLayout().getProgramAddressSpace()); // Get the type of a ctor entry, { i32, void ()*, i8* }. llvm::StructType *CtorStructTy = llvm::StructType::get( - Int32Ty, llvm::PointerType::getUnqual(CtorFTy), VoidPtrTy); + Int32Ty, CtorPFTy, VoidPtrTy); // Construct the constructor and destructor arrays. ConstantInitBuilder builder(*this); -- 2.34.1