Skip to content

[Flang][OpenMP] Parsing error or Semantics Crash for omp declare reduction #57219

Open
@kiranchandramohan

Description

@kiranchandramohan

Reproducer
Compiling the following program with a declare reduction,

subroutine reduce_1 ( n, locs )
  type :: loc
    integer :: x
    integer :: y
  end type
  integer :: n
  type(loc) :: locs(n)

  !$omp declare reduction(- : loc :  omp_out = loc(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = loc(0,0))

  type(loc) :: diffp = loc( 0, 0 )
  integer :: i

  !ERROR: The minus reduction operator is deprecated since OpenMP 5.2 and is not supported in the REDUCTION clause.
  !$omp parallel do reduction(- : diffp)
  do i = 1, n
     diffp%x = diffp%x - locs(i)%x
     diffp%y = diffp%y - locs(i)%y
  end do

end subroutine

produces the following error.

error: Could not parse ../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:13:31: error: expected 'LOGICAL'
    !$omp declare reduction(- : loc :  omp_out = loc(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = loc(0,0))
                                ^
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:13:31: in the context: intrinsic type spec
    !$omp declare reduction(- : loc :  omp_out = loc(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = loc(0,0))
                                ^
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:13:31: in the context: declaration type spec
    !$omp declare reduction(- : loc :  omp_out = loc(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = loc(0,0))
                                ^
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:13:3: in the context: specification construct
    !$omp declare reduction(- : loc :  omp_out = loc(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = loc(0,0))
    ^
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:13:3: in the context: declaration construct
    !$omp declare reduction(- : loc :  omp_out = loc(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = loc(0,0))
    ^
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:6:3: in the context: specification part
    type :: loc
    ^   
./../flang/test/Semantics/OpenMP/omp-declarative-reduction-subtract.f90:5:1: in the context: SUBROUTINE subprogram
  subroutine reduce_1 ( n, locs )
  ^
~     

Note 1: Changing loc to type(loc) produces a semantics crash.
Note 2: Intel compiler accepts the above code.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions