| Issue |
239695
|
| Summary |
[flang] [semantics] Missing errors for an assumed-type actual argument
|
| Labels |
flang:semantics
|
| Assignees |
vntkmr
|
| Reporter |
vntkmr
|
(Prepared with the help of AI.)
flang accepts calls in which an assumed-type (`TYPE(*)`) actual argument breaks rules that flang enforces for other actual arguments: C1548, definability for an INTENT(INOUT) dummy argument, and the rank rules for an assumed-shape dummy argument. The same calls with a REAL actual argument are errors.
## Reproducer
```fortran
module m
contains
subroutine t_contiguous(x)
type(*), volatile, contiguous :: x(:)
end subroutine
subroutine t_assumed_size(x)
type(*), volatile :: x(*)
end subroutine
subroutine t_inout(x)
type(*), intent(inout) :: x(:)
end subroutine
subroutine t_rank2(x)
type(*) :: x(:,:)
end subroutine
subroutine t_array(x)
type(*) :: x(:)
end subroutine
subroutine r_contiguous(x)
real, volatile, contiguous :: x(:)
end subroutine
subroutine r_assumed_size(x)
real, volatile :: x(*)
end subroutine
subroutine r_inout(x)
real, intent(inout) :: x(:)
end subroutine
subroutine r_rank2(x)
real :: x(:,:)
end subroutine
subroutine r_array(x)
real :: x(:)
end subroutine
! flang reports none of these calls.
subroutine assumed_type_actuals(vol, inp, arr, scl)
type(*), volatile :: vol(:)
type(*), intent(in) :: inp(:)
type(*) :: arr(:), scl
call t_contiguous(vol)
call t_assumed_size(vol)
call t_inout(inp)
call t_rank2(arr)
call t_array(scl)
end subroutine
! flang reports all five calls.
subroutine real_actuals(vol, inp, arr, scl)
real, volatile :: vol(:)
real, intent(in) :: inp(:)
real :: arr(:), scl
call r_contiguous(vol)
call r_assumed_size(vol)
call r_inout(inp)
call r_rank2(arr)
call r_array(scl)
end subroutine
end module
```
```
$ flang -fsyntax-only repro.f90
error: Semantic errors in repro.f90
repro.f90:52:23: error: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='
repro.f90:53:25: error: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='
repro.f90:54:18: error: Actual argument associated with INTENT(IN OUT) dummy argument 'x=' is not definable
repro.f90:55:18: error: Rank of dummy argument is 2, but actual argument has rank 1
repro.f90:56:18: error: Scalar actual argument may not be associated with assumed-shape dummy argument 'x='
```
Only the calls in `real_actuals` are reported. The assumed-type calls at lines 40 to 44 break the same rules and get no error.
flang version 24.0.0git (llvm-project `6d7b8f3c0dd6`), the flang-trunk build on Compiler Explorer.
## Expected behavior
All ten calls are errors. Each assumed-type call matches the REAL call 12 lines below it (F2023):
- Lines 40 and 52 violate C1548. `vol` is a nonpointer VOLATILE array that isn't simply contiguous, and the dummy argument is VOLATILE and CONTIGUOUS.
- Lines 41 and 53 also violate C1548. The VOLATILE dummy argument is assumed-size, and C1548 requires it to be assumed-shape or assumed-rank.
- Lines 42 and 54 violate 15.5.2.5 p20. The actual argument for an INTENT(INOUT) dummy argument must be definable, and `inp` is INTENT(IN).
- Lines 43 and 55 violate 15.5.2.5 p16. An assumed-shape dummy argument requires an actual argument of the same rank.
- Lines 44 and 56 violate 15.5.2.5 p14. A noncoindexed scalar actual argument requires a scalar dummy argument, and none of the exceptions in p14 applies.
C715 allows an assumed-type name as an actual argument that corresponds to an assumed-type dummy argument, so each assumed-type call is otherwise valid, and none of these rules exempts assumed type. Cray Fortran 19.0.0 reports lines 41 to 44 and 53 to 56. It doesn't report C1548 for a CONTIGUOUS dummy argument (lines 40 and 52) with either type.
## Cause
A plain assumed-type actual argument is an `ActualArgument::AssumedType`, not an _expression_. `CheckExplicitInterfaceArg` in `flang/lib/Semantics/check-call.cpp` passes an _expression_ to `checkOneExpr`, which calls `CheckExplicitDataArg`. For an assumed-type argument, it checks only that the dummy argument is assumed-type, and C716 for an assumed-rank dummy argument:
https://github.com/llvm/llvm-project/blob/ca28b513e26988fb93f0f12f9de1067486039991/flang/lib/Semantics/check-call.cpp#L1752-L1767
`CheckExplicitDataArg` holds every check that reports the REAL calls: the rank and scalar checks, the definability check, and C1548.
## Possible fix
Move the checks that need only the actual argument's attributes, shape, contiguity, and definability out of `CheckExplicitDataArg`, so that the assumed-type branch can run them with the dummy argument's `Symbol`. I haven't tried this.
Found during review of #238055. That PR makes flang report C1548 for an assumed-type consequent-arg of a conditional argument, such as `(flag ? a : b)`. A consequent-arg is an _expression_, so it goes through `CheckExplicitDataArg`.
(Prepared with the help of AI.)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs