]> granicus.if.org Git - clang/commitdiff
Use the correct address space when bitcasting func pointer to int pointer
authorDylan McKay <me@dylanmckay.io>
Fri, 9 Nov 2018 19:42:05 +0000 (19:42 +0000)
committerDylan McKay <me@dylanmckay.io>
Fri, 9 Nov 2018 19:42:05 +0000 (19:42 +0000)
When we cast a function pointer to an int pointer, at some pointer later
it gets bitcasted back to a function and called.

In backends that have a nonzero program memory address space specified
in the data layout, the old code would lose the address space data. When
LLVM later attempted to generate the bitcast from i8* to i8(..)*
addrspace(1), it would fail because the pointers are not in the same
address space.

With this patch, the address space of the function will carry on to the
address space of the i8* pointer. This is because all function pointers
in Harvard architectures need to be assigned to the correct address
space.

This has no effect to any in-tree backends except AVR.

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

lib/CodeGen/CGException.cpp

index e77d0988dc6f5c56904533b2fb2798fb0454e1d3..10b68e41f01f5d4c468f43bec02e08b279fdd6d3 100644 (file)
@@ -250,7 +250,11 @@ static llvm::Constant *getPersonalityFn(CodeGenModule &CGM,
 static llvm::Constant *getOpaquePersonalityFn(CodeGenModule &CGM,
                                         const EHPersonality &Personality) {
   llvm::Constant *Fn = getPersonalityFn(CGM, Personality);
-  return llvm::ConstantExpr::getBitCast(Fn, CGM.Int8PtrTy);
+  llvm::PointerType* Int8PtrTy = llvm::PointerType::get(
+      llvm::Type::getInt8Ty(CGM.getLLVMContext()),
+      CGM.getDataLayout().getProgramAddressSpace());
+
+  return llvm::ConstantExpr::getBitCast(Fn, Int8PtrTy);
 }
 
 /// Check whether a landingpad instruction only uses C++ features.