<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/136523>136523</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[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
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ohno-fj
</td>
</tr>
</table>
<pre>
```
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
$
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVkFv2zgT_TX0hahAkbIjHXRQ7Pr7elugxV6LkURZbGhSIKmk_veLoeRGVpwtgt3jBkEiijPvzbwZUgPeq5ORsiTbR7I9bGAMvXWl7Y391P3Y1La9lGTH5l9W_SmdV9ZQ29FOgzlRIirK04QljPBc1jVstxkInqY1q4u8FSCFqOGBdUW7ayRAvYM2I7wg_FhVrul3GWHVkoGwqmoa61plTjRYSnbsaF1wYKgPYFpwLeWMi8icsoQnaSLoFxOkG5wMEObwlAlOGa8aOuV4liZ4pBAVJaz6YmjoJYUQoOllSwdnTw7OhO-p6uKWluYUeoQiO_YMTkGtJSU8B99gAjtGlacnJyFIR0MP5q2b_Dk46aNihOeoMeePB8I54XvC-R7_kO1hgkNuRHgGPUoEwMUCQXn64lQI0qAundI6WtQazJOndqJ36tQH3K9lXHs4_4oJ_Iw_5ZJQOun9f_sin6VDfrJjo9HqrAJqYvXlbN3Qo4jOweVN9sYGCsMgTStb-qKQY4onoZVpES0WEtxlAvCI0PTpK8J97ymub72kndXavmAvgJsyCtKHZbmO2If48L9u7hMwLVXdT9rY86B07AjCj_KnbMbYHU76UYeZ5Pjt-1epZRO-XQb5nWdJV2CPLLtyxiWsmmnpGRQuKQ2XQdJwwedGg_dYZV7F_t6D1raBMLWNqLDxmiE4NBHRBAGkaZcg8ZnwPFwIL65etv6RRoYeHDQBK5VraYg4CISJRk9PlAjsrKqqsKkQ6x17vqf3QsOqLCKbTeS1YPnkO0W92IzB8e2cGZ8IvB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