[clang] [CIR] Add address space casts for pointer arguments when creating a call (PR #192303)

Jan Leyonberg via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 15 12:54:19 PDT 2026


================
@@ -1109,6 +1109,19 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo,
       if (argType != v.getType() && mlir::isa<cir::IntType>(v.getType()))
         cgm.errorNYI(loc, "emitCall: widening integer call argument");
 
+      // If we have a pointer argument and there's an address space mismatch,
+      // insert an address_space cast to match the expected function signature.
+      if (argType != v.getType()) {
+        auto argPtrTy = mlir::dyn_cast<cir::PointerType>(argType);
+        auto vPtrTy = mlir::dyn_cast<cir::PointerType>(v.getType());
+        if (argPtrTy && vPtrTy &&
+            argPtrTy.getPointee() == vPtrTy.getPointee() &&
+            argPtrTy.getAddrSpace() != vPtrTy.getAddrSpace()) {
+          v = builder.create<cir::CastOp>(loc, argPtrTy,
+                                          cir::CastKind::address_space, v);
----------------
jsjodin wrote:

Oh yes, I assumed it wasn't available for CIR since I didn't see it used in that file. Should have looked a bit more carefully. Fixed!

https://github.com/llvm/llvm-project/pull/192303


More information about the cfe-commits mailing list