[PATCH] Bug 18567: Fix constantexpr pointer casts with address spaces.
Matt Arsenault
Matthew.Arsenault at amd.com
Thu Jan 23 10:42:15 PST 2014
Getting a pointer into a struct at a non-zero offset would try to use the default address space.
http://llvm-reviews.chandlerc.com/D2607
Files:
lib/CodeGen/CGExprConstant.cpp
test/CodeGenOpenCL/address-space-constant-initializers.cl
Index: lib/CodeGen/CGExprConstant.cpp
===================================================================
--- lib/CodeGen/CGExprConstant.cpp
+++ lib/CodeGen/CGExprConstant.cpp
@@ -1063,7 +1063,9 @@
// Apply offset if necessary.
if (!Offset->isNullValue()) {
- llvm::Constant *Casted = llvm::ConstantExpr::getBitCast(C, Int8PtrTy);
+ unsigned AS = C->getType()->getPointerAddressSpace();
+ llvm::Type *CharPtrTy = Int8Ty->getPointerTo(AS);
+ llvm::Constant *Casted = llvm::ConstantExpr::getBitCast(C, CharPtrTy);
Casted = llvm::ConstantExpr::getGetElementPtr(Casted, Offset);
C = llvm::ConstantExpr::getPointerCast(Casted, C->getType());
}
Index: test/CodeGenOpenCL/address-space-constant-initializers.cl
===================================================================
--- /dev/null
+++ test/CodeGenOpenCL/address-space-constant-initializers.cl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -ffake-address-space-map -emit-llvm -o - | FileCheck %s
+
+typedef struct {
+ int i;
+ float f; // At non-zero offset.
+} ArrayStruct;
+
+__constant ArrayStruct constant_array_struct = { 0, 0.0f };
+
+typedef struct {
+ __constant float* constant_float_ptr;
+} ConstantArrayPointerStruct;
+
+// CHECK: %struct.ConstantArrayPointerStruct = type { float addrspace(3)* }
+// CHECK: addrspace(3) global %struct.ConstantArrayPointerStruct { float addrspace(3)* bitcast (i8 addrspace(3)* getelementptr (i8 addrspace(3)* bitcast (%struct.ArrayStruct addrspace(3)* @constant_array_struct to i8 addrspace(3)*), i64 4) to float addrspace(3)*) }
+// Bug 18567
+__constant ConstantArrayPointerStruct constant_array_pointer_struct = {
+ &constant_array_struct.f
+};
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2607.1.patch
Type: text/x-patch
Size: 1725 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140123/acf24831/attachment.bin>
More information about the cfe-commits
mailing list