Issue 138810
Summary [Flang] Incorrect execution result when reshape intrinsic function is specified as the argument of function
Labels flang
Assignees
Reporter ohno-fj
    ```
Version of flang : 21.0.0(842e5915778a820c63cf38b75bec932a6ea8c18b)/AArch64
```

When `reshape intrinsic function` is specified as the argument of `function (ch and s)`, the function result is incorrect.  
The above program is Polymorphism_22.f90.  
Once the result of `reshape intrinsic function` is assigned to a variable, and that variable is specified as an argument to `function (ch and s)`, the execution result is correct.

- Before modification
```
  call s(ch(reshape([2,3,5,6],[2,2])))
```
- After modification
```
  integer::res(2,2)
  res=reshape([2,3,5,6],[2,2])
 call s(ch(res))
```
The above program is Polymorphism_4.f90.

The following are the test program, Flang, Gfortran and ifx compilation/execution result.

Polymorphism_22.f90:
```fortran
program main
  interface
 subroutine s(unlim)
       class(*) :: unlim(:,:)
     end subroutine s
 function ch(dum)
       integer,pointer :: ch(:,:)
       integer,target :: dum(:,:)
     end function ch
  end interface
  call s(ch(reshape([2,3,5,6],[2,2])))
end program main

subroutine s(unlim)
 interface
     function fun(dmy)
       integer :: fun
       class(*):: dmy(2,2)
     end function fun
  end interface
  class(*) :: unlim(:,:)
 integer :: stat = 0
  stat = fun(unlim)
  if(stat/=1) then
 print*,101
  else
     print*,'PASS'
  endif
end subroutine s

function fun(dmy)
  integer :: fun
  class(*):: dmy(2,2)
  if(sizeof(dmy) /= (4*4)) print*,'201'
  fun=0
  select type(dmy)
  type is(complex)
 print*,'202'
  type is(integer)
!     if(dmy(2,1)/=3) print*,203
 print*, "dmy = ", dmy
     fun=1
  end select
end function fun

function ch(dum)
  integer,pointer :: ch(:,:)
  integer,target :: dum(:,:)
  ch=>dum
end function ch
```

```
$ flang Polymorphism_22.f90; ./a.out
 dmy =  -1431332800 10 -418684532 -878184479
 PASS
$
```

```
$ gfortran Polymorphism_22.f90; ./a.out
 dmy = 2           3           5           6
 PASS
$
```

```
$ ifx Polymorphism_22.f90; ./a.out
 dmy =            2           3           5 6
 PASS
$
```


Polymorphism_4.f90:
```fortran
program main
 interface
     subroutine s(unlim)
       class(*) :: unlim(:,:)
     end subroutine s
     function ch(dum)
       integer,pointer :: ch(:,:)
 integer,target :: dum(:,:)
     end function ch
  end interface
 integer::res(2,2)
  res=reshape([2,3,5,6],[2,2])
  call s(ch(res))
end program main

subroutine s(unlim)
  interface
     function fun(dmy)
 integer :: fun
       class(*):: dmy(2,2)
     end function fun
  end interface
  class(*) :: unlim(:,:)
  integer :: stat = 0
  stat = fun(unlim)
  if(stat/=1) then
     print*,101
  else
     print*,'PASS'
 endif
end subroutine s

function fun(dmy)
  integer :: fun
  class(*):: dmy(2,2)
  if(sizeof(dmy) /= (4*4)) print*,'201'
  fun=0
  select type(dmy)
  type is(complex)
     print*,'202'
  type is(integer)
! if(dmy(2,1)/=3) print*,203
     print*, "dmy = ", dmy
     fun=1
  end select
end function fun

function ch(dum)
  integer,pointer :: ch(:,:)
 integer,target :: dum(:,:)
  ch=>dum
end function ch
```

```
$ flang Polymorphism_4.f90; ./a.out
 dmy =  2 3 5 6
 PASS
$
```

```
$ gfortran Polymorphism_4.f90; ./a.out
 dmy =            2           3 5           6
 PASS
$
```

```
$ ifx Polymorphism_4.f90; ./a.out
 dmy =            2           3           5           6
 PASS
$
```


_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to