Issue 141807
Summary [flang] Incorrect generic resolution of ASSIGNMENT(=)
Labels flang:frontend
Assignees
Reporter DanielCChen
    Consider the following code:
```
module m

   type base
      integer(4) :: i = -999
      contains
         procedure, pass(b) :: array_scalar
 procedure, pass    :: elemental
         generic :: assignment(=) => array_scalar,elemental
   end type

   contains

   subroutine array_scalar ( a, b )
      class(base), intent(out) :: a(:)
 class(base), intent(in)  :: b

      print *,'array_scalar'
      do i =0, size(a)-1
         a(i+1)%i = b%i + i
      end do


   end subroutine

   impure elemental subroutine elemental ( a, b )
 class(base), intent(out) :: a
      class(base), intent(in)  :: b

 print*, "elemental"
      a%i = b%i + 1

   end subroutine

end module

program genericAssignmentPass011
   use m

   class(base), allocatable :: b1, b2(:)

   allocate (b1, b2(3))

   b1 = base(100)
 print *, b1%i

   b2 = b1                     !! ERROR: should resolve to subroutine "array_scalar" rather than "elemental"
   print *, b2%i


end program
```

The defined assignment `b2 = b1` has a more specific subroutine (`array_scalar`) to resolve to rather than the elemental subroutine `elemental`. 

All ifort, gfortran and XLF outputs the same expected result.
```
 elemental
         101
 array_scalar
         101 102         103
```

But Flang has
```
 elemental
 101
 elemental
 elemental
 elemental
 102 102 102
```

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

Reply via email to