[flang-commits] [flang] [Flang] Handle %VAL arguments correctly (PR #157186)
Carlos Seo via flang-commits
flang-commits at lists.llvm.org
Mon Sep 8 10:07:59 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());
----------------
ceseo wrote:
I think that's the case because `hlfir::loadTrivialScalar` always creates `fir::LoadOp` for scalar trivial variables coming from `hlfir.declare`.
https://github.com/llvm/llvm-project/pull/157186
More information about the flang-commits
mailing list