llvm-project/flang/test/Semantics/OpenMP/cray-pointer-usage.f90
Krish Gupta b76c84e70f
[flang][OpenMP] Fix crash when arrays used in LINEAR clause (#175383)
Closes #171007

Found this crash while testing OpenMP code - turns out putting an array
in a LINEAR clause on SIMD directives causes the compiler to blow up
with "unknown LLVM dialect type" and hit an UNREACHABLE.

The issue is that LINEAR clauses only accept scalar variables (rank 0),
but we weren't checking for that early enough. The invalid array type
would slip through semantic analysis and then crash during MLIR to LLVM
IR translation when it tried to convert the type.

**What changed:**
- Added a rank check in the LINEAR clause validation to catch arrays up
front
- Made an exception for `declare simd` with the REF modifier since
that's actually allowed per spec
- Added tests covering different array types (1D, multi-dim,
assumed-shape)
- Updated existing tests that now catch the new error

Tested with the original reproducer and it now fails cleanly with a
proper error message instead of crashing.
2026-01-12 14:25:55 -06:00

46 lines
1.5 KiB
Fortran

!RUN: %python %S/../test_errors.py %s %flang -fopenmp
subroutine test_cray_pointer_usage
implicit none
integer :: i
real(8) :: var(*), pointee(2)
pointer(ivar, var)
! ERROR: Cray Pointee 'var' may not appear in LINEAR clause
! ERROR: List item 'var' in LINEAR clause must be a scalar variable
! ERROR: The list item 'var' specified without the REF 'linear-modifier' must be of INTEGER type
! ERROR: The list item `var` must be a dummy argument
!$omp declare simd linear(var)
pointee = 42.0
ivar = loc(pointee)
!$omp parallel num_threads(2) default(none)
! ERROR: The DEFAULT(NONE) clause requires that the Cray Pointer 'ivar' must be listed in a data-sharing attribute clause
print *, var(1)
!$omp end parallel
! ERROR: Cray Pointee 'var' may not appear in PRIVATE clause, use Cray Pointer 'ivar' instead
!$omp parallel num_threads(2) default(none) private(var)
print *, var(1)
!$omp end parallel
! ERROR: Cray Pointee 'var' may not appear in SHARED clause, use Cray Pointer 'ivar' instead
!$omp parallel num_threads(2) default(none) shared(var)
print *, var(1)
!$omp end parallel
! ERROR: Cray Pointee 'var' may not appear in LASTPRIVATE clause, use Cray Pointer 'ivar' instead
!$omp do lastprivate(var)
do i = 1, 10
print *, var(1)
end do
!$omp end do
!$omp parallel num_threads(2) default(none) firstprivate(ivar)
print *, var(1)
!$omp end parallel
!$omp parallel num_threads(2) default(private) shared(ivar)
print *, var(1)
!$omp end parallel
end subroutine test_cray_pointer_usage