Re: r346548 - Use the correct address space when bitcasting func pointer to int pointer

2018-11-09 Thread Roman Lebedev via cfe-commits
The codegen change can't be tested?
On Fri, Nov 9, 2018 at 10:44 PM Dylan McKay via cfe-commits
 wrote:
>
> Author: dylanmckay
> Date: Fri Nov  9 11:42:05 2018
> New Revision: 346548
>
> URL: http://llvm.org/viewvc/llvm-project?rev=346548=rev
> Log:
> Use the correct address space when bitcasting func pointer to int pointer
>
> 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.
>
> Modified:
> cfe/trunk/lib/CodeGen/CGException.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGException.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=346548=346547=346548=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGException.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGException.cpp Fri Nov  9 11:42:05 2018
> @@ -250,7 +250,11 @@ static llvm::Constant *getPersonalityFn(
>  static llvm::Constant *getOpaquePersonalityFn(CodeGenModule ,
>  const EHPersonality ) {
>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.
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r346548 - Use the correct address space when bitcasting func pointer to int pointer

2018-11-09 Thread Dylan McKay via cfe-commits
Author: dylanmckay
Date: Fri Nov  9 11:42:05 2018
New Revision: 346548

URL: http://llvm.org/viewvc/llvm-project?rev=346548=rev
Log:
Use the correct address space when bitcasting func pointer to int pointer

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.

Modified:
cfe/trunk/lib/CodeGen/CGException.cpp

Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=346548=346547=346548=diff
==
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Fri Nov  9 11:42:05 2018
@@ -250,7 +250,11 @@ static llvm::Constant *getPersonalityFn(
 static llvm::Constant *getOpaquePersonalityFn(CodeGenModule ,
 const EHPersonality ) {
   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.


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits