Issue |
140941
|
Summary |
Flang semantic error depending on definition order of size/dimension arguments
|
Labels |
flang
|
Assignees |
|
Reporter |
hansec
|
Hello,
Flang (20.1.5) currently fails in some cases where a size argument, that is also an argument itself is defined after it’s first use. For example, the following simple test case
```fortran
MODULE test_mod
IMPLICIT NONE
CONTAINS
SUBROUTINE test_sub(a,n)
INTEGER(4), INTENT(in) :: a(n)
INTEGER(8), INTENT(in) :: n
END SUBROUTINE test_sub
END MODULE test_mod
```
results in the error
```
./test.F90:6:27: error: The type of 'n' has already been implicitly declared
INTEGER(8), INTENT(in) :: n
^
./test.F90:4:23: Implicit declaration of 'n'
SUBROUTINE test_sub(a,n)
^
```
Note that while the error points to the subroutine definition the actual error appears to be caused by implicit definition of `n` in the declaration of `a`. Indeed, if `n` is defined before `a` or if `n` is of default integer type (4 bytes in this case) the error is not thrown.
To be explicit both of the following work
```fortran
INTEGER(4), INTENT(in) :: a(n)
INTEGER, INTENT(in) :: n
```
```fortran
INTEGER(8), INTENT(in) :: n
INTEGER(4), INTENT(in) :: a(n)
```
I am not sure if this is Flang being pedantic or not, but every other Fortran compiler I work with (Intel, GCC, Cray) supports this ordering of code so it would be nice to not have to change things just to support Flang. This seems somewhat related to [#106021](https://github.com/llvm/llvm-project/issues/106021).
I tried to look around to see if this was reported earlier but couldn’t find anything. So apologies if this is a repeat. Thanks!
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs