[PATCH] D150746: [CodeGen]Translating pointer arguments can require an address space cast

Alex Voicu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 17 05:56:42 PDT 2023


AlexVlx updated this revision to Diff 523019.
AlexVlx added a comment.

Corrected typo that was breaking the build; rewrote the AS-using branch to account for the (unsupported, but possible, I think?) case of typed pointers, which was showing up in some tests that haven't been ported to opaque pointers.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150746/new/

https://reviews.llvm.org/D150746

Files:
  clang/lib/CodeGen/CGCall.cpp


Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -5183,11 +5183,18 @@
             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 the argument doesn't match, perform a either a bitcast or an
+        // address space cast to coerce it. This can happen either due to
+        // trivial type mismatches or valid address space mismatches
+        // (e.g. global -> generic; GEPs into VTTs are an example).
         if (FirstIRArg < IRFuncTy->getNumParams() &&
-            V->getType() != IRFuncTy->getParamType(FirstIRArg))
-          V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg));
+            V->getType() != IRFuncTy->getParamType(FirstIRArg)) {
+          llvm::Type *IRTy = IRFuncTy->getParamType(FirstIRArg);
+          if (V->getType()->isPointerTy())
+            V = Builder.CreatePointerBitCastOrAddrSpaceCast(V, IRTy);
+          else
+            V = Builder.CreateBitCast(V, IRTy);
+        }
 
         if (ArgHasMaybeUndefAttr)
           V = Builder.CreateFreeze(V);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150746.523019.patch
Type: text/x-patch
Size: 1326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230517/b25a3891/attachment.bin>


More information about the cfe-commits mailing list