Anastasia created this revision.
Anastasia added reviewers: rjmccall, ebevhan.
This is fixing one of the issues reported in the bug:
https://bugs.llvm.org/show_bug.cgi?id=40778
https://reviews.llvm.org/D58634
Files:
lib/CodeGen/CGCall.cpp
test/CodeGenOpenCLCXX/addrspace-references.cl
Index: test/CodeGenOpenCLCXX/addrspace-references.cl
===================================================================
--- /dev/null
+++ test/CodeGenOpenCLCXX/addrspace-references.cl
@@ -0,0 +1,11 @@
+//RUN: %clang_cc1 %s -cl-std=c++ -triple spir -emit-llvm -o - | FileCheck %s
+
+int bar(const unsigned int &i);
+
+void foo() {
+ // The generic addr space reference parameter object will be bound
+ // to a temporary value allocated in private addr space. We need an
+ // addrspacecast before passing the value to the function.
+ // CHECK: addrspacecast i32* %ref.tmp to i32 addrspace(4)*
+ bar(1);
+}
Index: lib/CodeGen/CGCall.cpp
===================================================================
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -4058,12 +4058,16 @@
if (ArgInfo.getCoerceToType() != V->getType() &&
V->getType()->isIntegerTy())
V = Builder.CreateZExt(V, ArgInfo.getCoerceToType());
-
// If the argument doesn't match, perform a bitcast to coerce it. This
// can happen due to trivial type mismatches.
if (FirstIRArg < IRFuncTy->getNumParams() &&
V->getType() != IRFuncTy->getParamType(FirstIRArg))
- V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg));
+ if (V->getType()->isPointerTy() &&
+ IRFuncTy->getParamType(FirstIRArg)->isPointerTy())
+ V = Builder.CreatePointerBitCastOrAddrSpaceCast(
+ V, IRFuncTy->getParamType(FirstIRArg));
+ else
+ V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg));
IRCallArgs[FirstIRArg] = V;
break;
Index: test/CodeGenOpenCLCXX/addrspace-references.cl
===================================================================
--- /dev/null
+++ test/CodeGenOpenCLCXX/addrspace-references.cl
@@ -0,0 +1,11 @@
+//RUN: %clang_cc1 %s -cl-std=c++ -triple spir -emit-llvm -o - | FileCheck %s
+
+int bar(const unsigned int &i);
+
+void foo() {
+ // The generic addr space reference parameter object will be bound
+ // to a temporary value allocated in private addr space. We need an
+ // addrspacecast before passing the value to the function.
+ // CHECK: addrspacecast i32* %ref.tmp to i32 addrspace(4)*
+ bar(1);
+}
Index: lib/CodeGen/CGCall.cpp
===================================================================
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -4058,12 +4058,16 @@
if (ArgInfo.getCoerceToType() != V->getType() &&
V->getType()->isIntegerTy())
V = Builder.CreateZExt(V, ArgInfo.getCoerceToType());
-
// If the argument doesn't match, perform a bitcast to coerce it. This
// can happen due to trivial type mismatches.
if (FirstIRArg < IRFuncTy->getNumParams() &&
V->getType() != IRFuncTy->getParamType(FirstIRArg))
- V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg));
+ if (V->getType()->isPointerTy() &&
+ IRFuncTy->getParamType(FirstIRArg)->isPointerTy())
+ V = Builder.CreatePointerBitCastOrAddrSpaceCast(
+ V, IRFuncTy->getParamType(FirstIRArg));
+ else
+ V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg));
IRCallArgs[FirstIRArg] = V;
break;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits