]> granicus.if.org Git - clang/commitdiff
Use the correct address space when emitting the ctor function list
authorDylan McKay <me@dylanmckay.io>
Fri, 9 Nov 2018 17:15:06 +0000 (17:15 +0000)
committerDylan McKay <me@dylanmckay.io>
Fri, 9 Nov 2018 17:15:06 +0000 (17:15 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346520 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp

index f55fa3f1bcb7961c7cb4ff3bb1cbcfac6ab4f2f9..d62d8be195dfed08f06eaa694293f62fe05e02ea 100644 (file)
@@ -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);