[PATCH] When generating llvm.used, we may need an addrspacecast instead of a bitcast.

Justin Holewinski justin.holewinski at gmail.com
Mon Feb 2 13:07:37 PST 2015


REPOSITORY
  rL LLVM

http://reviews.llvm.org/D7345

Files:
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/test/CodeGenCUDA/llvm-used.cu

Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -935,8 +935,8 @@
   UsedArray.resize(List.size());
   for (unsigned i = 0, e = List.size(); i != e; ++i) {
     UsedArray[i] =
-     llvm::ConstantExpr::getBitCast(cast<llvm::Constant>(&*List[i]),
-                                    CGM.Int8PtrTy);
+        llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
+            cast<llvm::Constant>(&*List[i]), CGM.Int8PtrTy);
   }
 
   if (UsedArray.empty())
Index: cfe/trunk/test/CodeGenCUDA/llvm-used.cu
===================================================================
--- cfe/trunk/test/CodeGenCUDA/llvm-used.cu
+++ cfe/trunk/test/CodeGenCUDA/llvm-used.cu
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -fcuda-is-device -triple nvptx64-unknown-unknown | FileCheck %s
+
+
+// Make sure we emit the proper addrspacecast for llvm.used.  PR22383 exposed an
+// issue where we were generating a bitcast instead of an addrspacecast.
+
+// CHECK: @llvm.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(1)* bitcast ([0 x i32] addrspace(1)* @a to i8 addrspace(1)*) to i8*)], section "llvm.metadata"
+__attribute__((device)) __attribute__((__used__)) int a[] = {};

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7345.19184.patch
Type: text/x-patch
Size: 1342 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150202/9c96bf84/attachment.bin>


More information about the llvm-commits mailing list