[flang-commits] [flang] [flang] Propagate INTENT(IN) dummy arguments as readonly (PR #207732)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Thu Jul 9 06:17:48 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,
+/// so the LLVM `readonly` argument attribute can be set. Notes on the
+/// exclusions:
+/// - VALUE, POINTER, and ALLOCATABLE dummies require ABI- or
+/// descriptor-specific handling before `readonly` can be applied and are
+/// left out of scope;
+/// - ASYNCHRONOUS memory may change underneath the callee;
+/// - VOLATILE+INTENT(IN) is prohibited by the standard (C870); kept here
+/// defensively.
+/// TARGET and derived types are intentionally allowed: any write that
+/// INTENT(IN) still permits (e.g. writing the target of a POINTER component)
+/// goes through a pointer loaded from the object, not through the argument
+/// pointer, and hence does not violate LLVM `readonly` (which only constrains
+/// the argument and pointers based on it).
+static bool dummyArgIsReadOnly(
----------------
eugeneepshteyn wrote:
Also, what about this:
```
subroutine inner(y)
integer :: y ! no intent — writes y
y = 99
end subroutine
subroutine outer(x)
integer, intent(in) :: x
call inner(x)
end subroutine
```
https://github.com/llvm/llvm-project/pull/207732
More information about the flang-commits
mailing list