[flang-commits] [flang] [flang][OpenMP] Fix crash when arrays used in LINEAR clause (PR #175383)

Krish Gupta via flang-commits flang-commits at lists.llvm.org
Mon Jan 12 06:53:24 PST 2026


KrxGu wrote:

@NimishMishra Thanks for the review! I've verified our implementation against the OpenMP 5.2 specification (Section 5.4.6). Here's what I found:

**For Fortran, the LINEAR clause restrictions state:**
- **Without ref modifier**: all list items must be of type integer (i.e., scalar integers)
- **With ref modifier**: list items can be polymorphic variables, assumed-shape arrays, or ALLOCATABLE variables

**However**, the spec also states:
> "A linear-modifier may be specified as ref or uval **only on a declare simd directive**."

So for the crash reproducer:
```fortran
!$omp simd linear(arr)  ! arr is an array
```

This is **invalid** because:
1. It's a regular `simd` directive (not `declare simd`), so no `ref` modifier is allowed
2. Without `ref`, the list item must be a scalar integer

Our implementation correctly:
- Rejects arrays in `linear` on `simd` directives
- Allows arrays in `linear(ref(...))` on `declare simd` directives (see our test in simd-linear-array.f90)

**Regarding gfortran**: Could you share the test case that gfortran accepts? If it's accepting arrays without `ref` modifier on a regular `simd`, that might be a gfortran bug or extension. I'd be happy to investigate further with a specific example.

https://github.com/llvm/llvm-project/pull/175383


More information about the flang-commits mailing list