From: Pekka Jaaskelainen Date: Fri, 19 Dec 2014 18:04:27 +0000 (+0000) Subject: Fix an address space id reset with array decay's X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1e101d03e5d4f99e2558573a3e37847d3930117a;p=clang Fix an address space id reset with array decay's implicit conversion. The issue was produced with OpenCL C code that called a function with a constant string literal argument. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224592 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index a4430dffb0..0fef4462eb 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -1412,7 +1412,8 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) { if (!E->getType()->isVariableArrayType()) { assert(isa(V->getType()) && "Expected pointer"); V = CGF.Builder.CreatePointerCast( - V, ConvertType(E->getType())->getPointerTo()); + V, ConvertType(E->getType())->getPointerTo( + V->getType()->getPointerAddressSpace())); assert(isa(V->getType()->getPointerElementType()) && "Expected pointer to array"); diff --git a/test/CodeGenOpenCL/const-str-array-decay.cl b/test/CodeGenOpenCL/const-str-array-decay.cl new file mode 100644 index 0000000000..dbbe08989c --- /dev/null +++ b/test/CodeGenOpenCL/const-str-array-decay.cl @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -ffake-address-space-map | FileCheck %s + +int test_func(constant char* foo); + +kernel void str_array_decy() { + test_func("Test string literal"); +} + +// CHECK: i8 addrspace(3)* getelementptr inbounds ([20 x i8] addrspace(3)* +// CHECK-NOT: addrspacecast +