Issue |
136523
|
Summary |
[Flang] Incorrect execution result of assigning the value of an _expression_ when the length of the variable is greater than the length of the _expression_
|
Labels |
flang
|
Assignees |
|
Reporter |
ohno-fj
|
```
Version of flang : 21.0.0(ebba554a3211b0b98d3ae33ba70f9d6ceaab6ad4)/AArch64
```
According to `Fortran standard 2023 : 10.2.1.3 Interpretation of intrinsic assignments`:
In the attached program, if the length of `variable (asc)` is greater than the length of `_expression_ (["BD","CC"])`, the value of the _expression_ is written to fill the blanks on the right to be the same length as the variable.
However, `unlimited polymorphic array (asc)` is not appended with a blank. And `ordinary arrays (ch1)` is appended with a blank.
The following are the test program, Flang, Gfortran and ifx compilation/execution result.
FT_SelectType_24.f90:
```fortran
program main
type ty
class(*),allocatable :: cptr(:)
end type ty
type(ty) :: obj1
character(len=3)::kk ="AAA"
character(len=3), allocatable :: ch1(:)
allocate(ch1(3))
allocate(obj1%cptr(2),source=kk)
select type(asc=>obj1%cptr)
type is(character(len=*))
ch1 = ["BD","CC"]
write(6,*) "len(ch1(1)) = ", len(ch1(1)), " ch1(1) = ", ch1(1)
write(6,*) "len(ch1(2)) = ", len(ch1(2)), " ch1(2) = ", ch1(2)
asc = ["BD","CC"]
write(6,*) "len(asc(1)) = ", len(asc(1)), " asc(1) = ", asc(1)
write(6,*) "len(asc(2)) = ", len(asc(2)), " asc(2) = ", asc(2)
class default
write(6,*) "error2"
end select
print*,"PASS"
end program main
```
```
$ flang FT_SelectType_24.f90; ./a.out
len(ch1(1)) = 3 ch1(1) = BD
len(ch1(2)) = 3 ch1(2) = CC
len(asc(1)) = 3 asc(1) = BDC
len(asc(2)) = 3 asc(2) = C
^@
PASS
$
```
```
$ gfortran FT_SelectType_24.f90; ./a.out
len(ch1(1)) = 3 ch1(1) = BD
len(ch1(2)) = 3 ch1(2) = CC
len(asc(1)) = 3 asc(1) = BD
len(asc(2)) = 3 asc(2) = CC
PASS
$
```
```
$ ifx FT_SelectType_24.f90; ./a.out
len(ch1(1)) = 3 ch1(1) = BD
len(ch1(2)) = 3 ch1(2) = CC
len(asc(1)) = 3 asc(1) = BD
len(asc(2)) = 3 asc(2) = CC
PASS
$
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs