[flang-commits] [flang] [flang] Disable copy-out to INTENT(IN) args (PR #192382)

via flang-commits flang-commits at lists.llvm.org
Thu Apr 16 10:22:05 PDT 2026


================
@@ -1649,6 +1649,17 @@ std::optional<bool> ActualArgNeedsCopy(const ActualArgument *actual,
     // Expressions are copy-in, but not copy-out.
     return forCopyIn;
   }
+  if (forCopyOut) {
+    // If the actual argument's base object has INTENT(IN) in the caller's
+    // context, copy-out would violate the read-only semantics of INTENT(IN).
+    if (const Expr<SomeType> *expr{actual->UnwrapExpr()}) {
+      if (const Symbol *symbol{GetFirstSymbol(*expr)}) {
----------------
jeanPerier wrote:

Can you check this does not bypasses copy-out for the following case where the base has INTENT(in) but what is passed is the target of a pointer component:

```
module m
 type t
   integer, pointer :: i(:)
 end type
end module

subroutine test_actual_arg_intent_in(x)
  use m, only : t
  type(t) , intent(in) :: x
  x%i(1) = 42
  call bar(x%i(:))
end subroutine
```

I am not 100% sure what is the standard requirement for these cases, but all the compilers I tested are OK with `x%i(1) = 42` while they complain on `x%j` where j is a simple components, so I assume it may be legal to modify such data.



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


More information about the flang-commits mailing list