[flang-commits] [flang] [Flang] Handle %VAL arguments correctly (PR #157186)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Mon Sep 8 09:21:00 PDT 2025


================
@@ -497,13 +497,12 @@ Fortran::lower::genCallOpAndResult(
 
     // Special handling for %VAL arguments: internal procedures expect
     // reference parameters. When %VAL is used, the argument should be
-    // passed by value. So we need to create a temporary variable and
-    // pass its address to avoid a type conversion error.
+    // passed by value. Pass the originally loaded value.
     if (fir::isa_ref_type(snd) && !fir::isa_ref_type(fst.getType()) &&
         fir::dyn_cast_ptrEleTy(snd) == fst.getType()) {
-      mlir::Value temp = builder.createTemporary(loc, fst.getType());
-      builder.create<fir::StoreOp>(loc, fst, temp);
-      cast = temp;
+      auto loadOp = mlir::cast<fir::LoadOp>(fst.getDefiningOp());
----------------
tblah wrote:

Thanks for the update. Please could you keep the old code creating the temporary as a fallback. I'm not 100% certain that there will always be a load here. If the cast failed that would be a compiler crash. I'd rather have 2 lines of dead code than a compiler crash for some obscure untested case.

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


More information about the flang-commits mailing list