llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Flang][OpenMP] Missing semantic check: LINEAR clause variable in statement function expression

Open blazie2004 opened this issue 6 months ago • 1 comments

Description:

Flang does not diagnose when a variable appearing in a statement function expression is specified in a LINEAR clause.

The Cray Fortran compiler (CCE) correctly diagnoses this:

ftn-1760: "X" is referenced in a statement function expression, so it must not be specified in the LINEAR clause.

Reproducer:

subroutine test()
  integer :: pi, r, f, x

  f(r) = pi * r + x

  !$omp parallel do linear(x)
  do r = 1, 10
    pi = f(r)
  end do
  !$omp end parallel do
end subroutine

Expected Behavior:

error: Variable 'x' in statement function expression cannot be in a LINEAR clause

Actual Behavior:

No diagnostic is emitted; compilation succeeds.

Specification References:

  • OpenMP 4.5, Section 2.15.3.7:

    A list item that appears in a linear clause is subject to the private clause semantics described in Section 2.15.3.3.

  • OpenMP 4.5, Section 2.15.3.3:

    Variables that appear in namelist statements, in variable format expressions, and in expressions for statement function definitions, may not appear in a private clause.

  • OpenMP 5.3, Section 5.3:

    Variables that appear in namelist statements, in variable format expressions, and in expressions for statement function definitions, must not be privatized.

Additional Notes:

Other compilers tested, including gfortran, flang, and ifort/ifx, currently accept the code without emitting a diagnostic, while CCE correctly rejects it.

blazie2004 avatar May 26 '26 11:05 blazie2004

@llvm/issue-subscribers-flang-frontend

Author: jay0x (blazie2004)

**Description:**

Flang does not diagnose when a variable appearing in a statement function expression is specified in a LINEAR clause.

The Cray Fortran compiler (CCE) correctly diagnoses this:

ftn-1760: "X" is referenced in a statement function expression, so it must not be specified in the LINEAR clause.

Reproducer:

subroutine test()
  integer :: pi, r, f, x

  f(r) = pi * r + x

  !$omp parallel do linear(x)
  do r = 1, 10
    pi = f(r)
  end do
  !$omp end parallel do
end subroutine

Expected Behavior:

error: Variable 'x' in statement function expression cannot be in a LINEAR clause

Actual Behavior:

No diagnostic is emitted; compilation succeeds.

Specification References:

  • OpenMP 4.5, Section 2.15.3.7:

    A list item that appears in a linear clause is subject to the private clause semantics described in Section 2.15.3.3.

  • OpenMP 4.5, Section 2.15.3.3:

    Variables that appear in namelist statements, in variable format expressions, and in expressions for statement function definitions, may not appear in a private clause.

  • OpenMP 5.3, Section 5.3:

    Variables that appear in namelist statements, in variable format expressions, and in expressions for statement function definitions, must not be privatized.

Additional Notes:

Other compilers tested, including gfortran, flang, and ifort/ifx, currently accept the code without emitting a diagnostic, while CCE correctly rejects it.