https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128993

            Bug ID: 128993
           Summary: [OpenMP] ICE in gfc_typenode_for_spec with linear (x:
                    val, step (expr)) on SIMD/DO: step expression never
                    resolved
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid, ice-on-valid-code, openmp
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lzy20000419 at outlook dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

Fails with trunk (gcc 17.0.0 20261124, 537d251e84e6) and with 13.1.0 through
16.2.0. 12.5.0 and older reject the OpenMP 5.2 syntax, so this is not a
regression.
Target: x86_64-pc-linux-gnu.

    subroutine s (a, b)
      implicit none
      integer :: a(:), b(*), i, j
      j = 1
      !$omp simd linear (j: val, step (size (a)))
      do i = 1, 10
        b(i) = j
        j = j + size (a)
      end do
    end

    gfortran -fopenmp -c t.f90

    t.f90:5:45:
    internal compiler error: in gfc_typenode_for_spec, at
fortran/trans-types.cc:1339

Expected: successful compilation. It compiles if "val," is removed, or if the
step is a constant or a plain variable. Any intrinsic call as the step ICEs, on
!$omp do too. With the VAL modifier, invalid code is also accepted: linear (j:
val, step (.true.)) and a REAL list item compile without an error.

Godbolt (trunk): https://godbolt.org/z/5hxaso1cz

Cause: in resolve_omp_clauses (fortran/openmp.cc), case OMP_LIST_LINEAR, the
checks are one if / else-if chain. On a DO or SIMD construct a VAL modifier
enters the first branch, which reports nothing because VAL is allowed there.
The else-if chain then skips the INTEGER check on the list item and the
gfc_resolve_expr call on the step. The step stays an unresolved EXPR_FUNCTION,
and gfc_trans_omp_clauses crashes on it.

Possible fix: make the list-item type check and the gfc_resolve_expr call on
the step a separate if after the modifier check, so an allowed VAL modifier
still reaches them. With that change on trunk, the testcase compiles, and
linear (j: val, step (.true.)) and a REAL list item are diagnosed.

Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.

Reply via email to