[Flang] No error checking if the type specifier specified in the allocate statement is different from the declaration
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:
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:
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/issue-subscribers-flang-frontend
Author: None (ohno-fj)
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:
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:
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/issue-subscribers-bug
Author: None (ohno-fj)
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:
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:
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)
^^^
$
@ceseo are you still going to fix this bug?
@klausler sorry, I was on vacation in the past weeks.
Yes, I was working on it today. However, I was looking at your initial implementation and I was wondering if this was intended behavior. So it's a real bug?
I don't know; when you assigned this issue to yourself, I assumed that you would investigate, and haven't analyzed it myself.
OK, I'll keep investigating. Fix is trivial, but it's breaking some tests.
@ohno-fj I was discussing this problem with @klausler . The situation described here is not actually a bug. The compiler should emit an error only when the character length values are distinct constants, which is not the case for c1s in your test.
@ceseo, thank you for your comment.
I understand the above.
In the second program (snggz792_12.f90), nn is declared as a constant with the parameter attribute attached, so it outputs an error when compiled. It works exactly as you commented.
Could you close this issue ?