[flang-commits] [flang] [flang] Avoid descriptor conversion for descriptor args with ignore_tkr(c) (PR #176240)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Mon Jan 19 18:02:22 PST 2026


================
@@ -495,6 +540,29 @@ Fortran::lower::genCallOpAndResult(
 
   mlir::FunctionType funcType =
       funcPointer ? callSiteType : caller.getFuncOp().getFunctionType();
+
+  // If we have any ignore_tkr(c) dummy args, adjust the function type to
+  // have these args match the caller.
+  mlir::FunctionType modifiedFuncType =
+      getTypeWithIgnoreTkrC(funcType, caller, builder.getContext());
+
+  // Note: funcPointer would only be non-null in this case, if we are already
+  // processing indirect function call. In such case we can re-use the same
+  // funcPointer and we'll cast it below the the modified funcType.
+  if (!funcPointer && modifiedFuncType != funcType) {
+    // We want to cast the function to a different type, in order to avoid
+    // changing/casting some of the args. The cast will generate a new
+    // function pointer, so that we would make a function call not through
+    // the original function symbol, but through the new function pointer
+    // (an indirect function call).
+    mlir::SymbolRefAttr symbolAttr =
+        builder.getSymbolRefAttr(caller.getMangledName());
+    // Create pointer to original function. This pointer will be cast later.
+    funcPointer = fir::AddrOfOp::create(builder, loc, funcType, symbolAttr);
+    funcSymbolAttr = {}; // This marks it as indirect call
+  }
+  funcType = modifiedFuncType;
----------------
eugeneepshteyn wrote:

Done

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


More information about the flang-commits mailing list