llvm / llvm/llvm-project

[Flang][OpenMP] Spurious error for atomic update of complex variable with a complex expression

Open
#191,384 3 comments 0 reactions 1 assignee Claimed by @kparzysz View on GitHub
flang:openmp
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Flang incorrectly rejects valid OpenMP atomic update code when the expression involves multiple additions.

Expected Behavior: The atomic update statement x = x + Y + Z should be accepted. According to the Fortran standard, X + Y + Z and X + (Y + Z) are equivalent forms. Since Flang accepts x = x + (Y + Z) without error, it should also accept x = x + Y + Z.

Actual Behavior: Flang produces the following errors:
```
error: The atomic variable x cannot be a proper subexpression of an argument (here: x+(0._4,1._4)) in the update operation
x = x + (0,1) + f()
error: The atomic variable x should appear as an argument of the top-level + operator
x = x + (0,1) + f()
```
Reproducer:

```fortran
Program test
Complex :: x
x = 0
!$OMP PARALLEL num_threads(2)

!$OMP ATOMIC
x = x + (0,1) + f()
!$OMP ATOMIC
x = x + (0,1) + f()
!$OMP END PARALLEL
if (x/=(4,4)) print *,x,'bug'
print '("ok")'
contains
Integer function f()
Complex :: w=(1,1)
f = w
End function
End
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.