| Issue |
78939
|
| Summary |
[Flang] No error checking if the type specifier specified in the allocate statement is different from the declaration
|
| Labels |
flang:frontend
|
| Assignees |
|
| Reporter |
ohno-fj
|
```
Version of flang-new : 18.0.0(0fe86f9c518fb1296bba8d66ce495f9dfff2c435)
```
When allocating a `character` type pointer variable, an error is not checked if the type specifier specified
in `allocate` statement is different from the declaration.
Gfortran and ifort detect compilation errors.
Specifying `parameter` attribute in the type declaration of the variable (nn) checks for errors. This program (snggz792_12.f90) and results are attached at the end.
The following are the test program, Flang-new, Gfortran and ifort compilation result.
snggz792_11.f90:
```fortran
module m1
integer::nn=1
! integer,parameter::nn=1
end module m1
program main
use m1
character(nn),pointer::c1s
kk=0
allocate(character(2)::c1s,stat=kk)
print *,kk
end program main
```
```
$ flang-new snggz792_11.f90
$
```
```
$ gfortran snggz792_11.f90
snggz792_11.f90:8:28:
8 | character(nn),pointer::c1s
| 1
Error: ‘c1s’ at (1) must have constant character length in this context
snggz792_11.f90:10:25:
10 | allocate(character(2)::c1s,stat=kk)
| 1
Error: Allocating c1s at (1) with type-spec requires the same character-length parameter as in the declaration
$
```
```
$ ifort snggz792_11.f90
snggz792_11.f90(8): error #6591: An automatic object is invalid in a main program. [C1S]
character(nn),pointer::c1s
-------------------------^
compilation aborted for snggz792_11.f90 (code 1)
$
```
snggz792_12.f90:
```fortran
module m1
! integer::nn=1
integer,parameter::nn=1
end module m1
program main
use m1
character(nn),pointer::c1s
kk=0
allocate(character(2)::c1s,stat=kk)
print *,kk
end program main
```
```
$ flang-new snggz792_12.f90
error: Semantic errors in snggz792_12.f90
./snggz792_12.f90:10:26: error: Character length of allocatable object in ALLOCATE must be the same as the type-spec
allocate(character(2)::c1s,stat=kk)
^^^
$
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs