Files
clang-p2996/flang/test/Semantics/OpenMP/atomic-update-only.f90
Krzysztof Parzyszek 141d390dcb [flang][OpenMP] Overhaul implementation of ATOMIC construct (#137852)
The parser will accept a wide variety of illegal attempts at forming an
ATOMIC construct, leaving it to the semantic analysis to diagnose any
issues. This consolidates the analysis into one place and allows us to
produce more informative diagnostics.

The parser's outcome will be parser::OpenMPAtomicConstruct object
holding the directive, parser::Body, and an optional end-directive. The
prior variety of OmpAtomicXyz classes, as well as OmpAtomicClause have
been removed. READ, WRITE, etc. are now proper clauses.

The semantic analysis consistently operates on "evaluation"
representations, mainly evaluate::Expr (as SomeExpr) and
evaluate::Assignment. The results of the semantic analysis are stored in
a mutable member of the OpenMPAtomicConstruct node. This follows a
precedent of having `typedExpr` member in parser::Expr, for example.
This allows the lowering code to avoid duplicated handling of AST nodes.

Using a BLOCK construct containing multiple statements for an ATOMIC
construct that requires multiple statements is now allowed. In fact, any
nesting of such BLOCK constructs is allowed.

This implementation will parse, and perform semantic checks for both
conditional-update and conditional-update-capture, although no MLIR will
be generated for those. Instead, a TODO error will be issues prior to
lowering.

The allowed forms of the ATOMIC construct were based on the OpenMP 6.0
spec.
2025-06-11 10:05:34 -05:00

84 lines
1.6 KiB
Fortran

!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=60
subroutine f00
integer :: x, y
! The x is a direct argument of the + operator. Expect no diagnostics.
!$omp atomic update
x = x + (y - 1)
end
subroutine f01
integer :: x
! x + 0 is unusual, but legal. Expect no diagnostics.
!$omp atomic update
x = x + 0
end
subroutine f02
integer :: x
! This is formally not allowed by the syntax restrictions of the spec,
! but it's equivalent to either x+0 or x*1, both of which are legal.
! Allow this case. Expect no diagnostics.
!$omp atomic update
x = x
end
subroutine f03
integer :: x, y
!$omp atomic update
!ERROR: The atomic variable x should occur exactly once among the arguments of the top-level + operator
x = (x + y) + 1
end
subroutine f04
integer :: x
real :: y
!$omp atomic update
!ERROR: This intrinsic function is not a valid ATOMIC UPDATE operation
x = floor(x + y)
end
subroutine f05
integer :: x
real :: y
! An explicit conversion is accepted as an extension.
!$omp atomic update
x = int(x + y)
end
subroutine f06
integer :: x, y
interface
function f(i, j)
integer :: f, i, j
end
end interface
!$omp atomic update
!ERROR: A call to this function is not a valid ATOMIC UPDATE operation
x = f(x, y)
end
subroutine f07
real :: x
integer :: y
!$omp atomic update
!ERROR: The ** operator is not a valid ATOMIC UPDATE operation
x = x ** y
end
subroutine f08
integer :: x, y
!$omp atomic update
!ERROR: The atomic variable x should appear as an argument in the update operation
x = y
end