Issue 135580
Summary [Flang] Incorrect execution result when the arguments described in SAME_TYPE_AS intrinsic function are defined in derived types with the same name but different definitions in different modules of different subroutines
Labels flang
Assignees
Reporter ohno-fj
    ```
Version of flang : 21.0.0(9fe6f6a0d430b872750354c20f3e4a651bd1f135)/AArch64
```

`The arguments (dmyptr and baseobj)` described in `SAME_TYPE_AS intrinsic function` are defined in `derived types` with `the same name (deriv)` but different definitions in different `modules (module3 and module4)` of different `subroutines (sub1 and sub2)`.  
Thus, the result of the `SAME_TYPE_AS intrinsic function` should be `F` because they are different types, even if they are defined by a `derived type` of the same name.

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

Polymorphism_FT_sametypeas_046_22.f90:
```fortran
MODULE MODULE3
  IMPLICIT NONE
  LOGICAL::x
  TYPE base
     integer ::int1
 END TYPE base
  TYPE ,EXTENDS(base)::deriv
     INTEGER :: int2
  END TYPE deriv
END MODULE MODULE3

MODULE MODULE4
  IMPLICIT NONE
  TYPE base
 INTEGER ::ii
  END TYPE base
  TYPE ,EXTENDS(base):: deriv
     INTEGER :: kk
  END TYPE deriv
END MODULE MODULE4

PROGRAM MAIN
  IMPLICIT NONE
  INTERFACE
     SUBROUTINE sub2
     END SUBROUTINE sub2
  END INTERFACE
  call sub2()
END PROGRAM MAIN

SUBROUTINE sub1(dmyptr)
  use MODULE3
  CLASS(*)::dmyptr
  TYPE(deriv)::baseobj
  LOGICAL::res
 res=SAME_TYPE_AS(dmyptr,baseobj)
  write(6,*) "res = ", res
END SUBROUTINE sub1

SUBROUTINE sub2()
  use MODULE4
  INTERFACE
 SUBROUTINE sub1(dmy1)
       CLASS(*)::dmy1
     END SUBROUTINE sub1
  end interface
  CLASS(base),POINTER::ptr_base
  TYPE(deriv),TARGET::tar_ty1
 ptr_base=>tar_ty1
  call sub1(ptr_base)
END SUBROUTINE sub2
```

```
$ flang Polymorphism_FT_sametypeas_046_22.f90; ./a.out
 res = T
$
```

```
$ gfortran Polymorphism_FT_sametypeas_046_22.f90; ./a.out
 res =  F
$
```

```
$ ifx Polymorphism_FT_sametypeas_046_22.f90; ./a.out
 res =  F
$
```

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

Reply via email to