[flang-commits] [flang] [flang] Propagate INTENT(IN) dummy arguments as readonly (PR #207732)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Mon Jul 6 16:46:12 PDT 2026


================
@@ -187,6 +187,30 @@ asImplicitArg(Fortran::evaluate::characteristics::DummyDataObject &&dummy) {
                                                        std::move(shape)));
 }
 
+/// An INTENT(IN) data object passed by reference is not modified by the callee,
----------------
vzakhari wrote:

Do we really need any lowering changes? `INTENT` is encoded in `[hl]fir.declare` already:
```
  func.func @_QPtest(%arg0: !fir.ref<f32> {fir.bindc_name = "x"}) {
    %0 = fir.dummy_scope : !fir.dscope
    %1:2 = hlfir.declare %arg0 dummy_scope %0 arg 1 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFtestEx"} : (!fir.ref<f32>, !fir.dscope) -> (!fir.ref<f32>, !fir.ref<f32>)
```

I think it should be possible to use `fortran_attrs` later to set `readonly`. I just do not see a reason to propagate the new attribute all the way from the lowering.

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


More information about the flang-commits mailing list