[flang-commits] [flang] [flang] Avoid unnecessary temporaries for PARAMETER actual arguments passed to INTENT(IN) dummies (PR #197636)
Yingying Wang via flang-commits
flang-commits at lists.llvm.org
Fri May 15 01:38:32 PDT 2026
buggfg wrote:
> Please see discussion about crashes and read-only memory in this PR: #187348
>
> (To clarify: it would be good to avoid extra copy-in/out of constants, we just want to do that in a way that covers any relevant corner cases beyond SPEC tests.)
yeah, compiler optimizations should target general use cases rather than special-casing a specific benchmark.
In the [array-call-chain.f90](https://godbolt.org/z/havzWchca) and [string-call-chain.f90](https://godbolt.org/z/9cG9YPnPG) test cases (PR #187348):
- Flang creates a temporary copy, so the program still runs even if the user violates the `INTENT(IN)` contract.
- GCC 15 does not create a temporary copy, and the program triggers a segmentation fault at runtime when attempting to modify read-only data.
I think users apply `INTENT(IN)` to explicitly express that an argument must not be modified, similar to `const` in C/C++. This is especially important in large projects to prevent accidental modification of arguments.
With this patch, the compiler will no longer automatically create temporary copies for such cases. If the user violates the `INTENT(IN)` contract and attempts to modify the data, the issue will surface immediately at runtime (for example, via a segmentation fault).
The main idea is to give the choice back to the user:
- either adjust/remove `INTENT(IN)` if modification is intended,
- or follow the `INTENT(IN)` contract and avoid modifying the argument.
https://github.com/llvm/llvm-project/pull/197636
More information about the flang-commits
mailing list