Skip to content

[flang] [FORALL] Incorrect dynamic type assigned within FORALL #153220

@DanielCChen

Description

@DanielCChen

Consider the following reducer:

  PROGRAM main
  IMPLICIT NONE
  TYPE :: DT
    CLASS(DT), POINTER    :: Ptr(:) => NULL()
  END TYPE

  TYPE, EXTENDS(DT) :: DT1
  END TYPE

  TYPE(DT1), TARGET  :: Tar1(100)
  CLASS(DT), POINTER :: T(:)
  integer :: I

  ALLOCATE(T(10))

  !DO I = 1, 10
  FORALL (I=1:10)            !! Wrong dynamic type assigned to T(I)%Ptr.
    T(I)%Ptr => Tar1
  END FORALL
  !end do

  DO I = 1, 10
    SELECT TYPE (aa => T(I)%Ptr)
    TYPE IS (DT1)
      print*, "in type is"
    CLASS DEFAULT
      print*, "in class default"
    END SELECT
  END DO

  END

Flang outputs

> a.out
 in class default
 in class default
 in class default
 in class default
 in class default
 in class default
 in class default
 in class default
 in class default
 in class default

The expected output is

> a.out
 in type is
 in type is
 in type is
 in type is
 in type is
 in type is
 in type is
 in type is
 in type is
 in type is

If I replace FORALL with the DO loop, Flang executes successfully.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions