[PATCH] D58634: [PR40778] Generate address space conversion when binding reference to a temporary value in different address space

Anastasia Stulova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 25 09:39:09 PST 2019


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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58634.188206.patch
Type: text/x-patch
Size: 1666 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190225/376dbf4f/attachment.bin>


More information about the cfe-commits mailing list