Open k-arrows opened 8 months ago
@llvm/issue-subscribers-flang-ir
Author: None (k-arrows)
@llvm/issue-subscribers-bug
Author: None (k-arrows)
This is not a bug but a correct error. gfortran will also report this error.
test.f90:22:9:
22 | call s(a, 4)
| 1
Error: Rank mismatch in argument 'a' at (1) (rank-1 and rank-2)
The rank of your array a
is 2 in the program and your subroutine expect a rank 1 array,
What we can try is to catch this error earlier to report it during the semantic analysis.
Well... it may actually be legal because the dummy is an explicit shape array, so the "Sequence association" described in Fortran 2018 standard section 15.5.2.11 may apply.
Point 5 says: "The rank and shape of the actual argument need not agree with the rank and shape of the dummy argument, but the number of elements in the dummy argument shall not exceed the number of elements in the element sequence of the actual argument."
There may be a (indirect?) restriction for polymorphic arguments, but I cannot find it.... xlf, ifort, and nvfortran all do compile and run correctly.
The issue is that we need to create a descriptor here, and I think we should likely pass one that is valid for the dummy (otherwise "static" reads of the incoming descriptor would be unsafe). But then we need to evaluate the dummy shape on the caller side, which should be possible (this is already done for array results), but is just adding more complexity in here (and this has to work OK with OPTIONAL...).
@klausler, do you agree we need to support this use case?
It's conforming usage of sequence association.
Compiling the following program with
-flang-experimental-polymorphism
causes a crash.Compile with:
flang-new -flang-experimental-polymorphism test.f90
Output:
Stack dump: