]> granicus.if.org Git - clang/commitdiff
Fix an address space id reset with array decay's
authorPekka Jaaskelainen <pekka.jaaskelainen@tut.fi>
Fri, 19 Dec 2014 18:04:27 +0000 (18:04 +0000)
committerPekka Jaaskelainen <pekka.jaaskelainen@tut.fi>
Fri, 19 Dec 2014 18:04:27 +0000 (18:04 +0000)
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

lib/CodeGen/CGExprScalar.cpp
test/CodeGenOpenCL/const-str-array-decay.cl [new file with mode: 0644]

index a4430dffb05ad7348ff4b841b42973ab891873fd..0fef4462eb9373e1dcbb5248a9df7da27b15d69c 100644 (file)
@@ -1412,7 +1412,8 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
     if (!E->getType()->isVariableArrayType()) {
       assert(isa<llvm::PointerType>(V->getType()) && "Expected pointer");
       V = CGF.Builder.CreatePointerCast(
-          V, ConvertType(E->getType())->getPointerTo());
+          V, ConvertType(E->getType())->getPointerTo(
+            V->getType()->getPointerAddressSpace()));
 
       assert(isa<llvm::ArrayType>(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 (file)
index 0000000..dbbe089
--- /dev/null
@@ -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
+