Skip to content

Conversation

@kparzysz
Copy link
Contributor

@kparzysz kparzysz commented Nov 5, 2025

Complex part designators do not have their own symbols. A symbol obtained for the expression x%re will be the symbol for x, and in this case x is allowed to be allocatable.

Fixes #166278.

Complex part designators do not have their own symbols. A symbol obtained
for the expression `x%re` will be the symbol for `x`, and in this case x
is allowed to be allocatable.

Fixes #166278.
@kparzysz kparzysz requested review from Meinersbur and tblah November 5, 2025 18:43
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:openmp flang:semantics labels Nov 5, 2025
@kparzysz kparzysz requested a review from kkwli November 5, 2025 18:43
@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2025

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-semantics

Author: Krzysztof Parzyszek (kparzysz)

Changes

Complex part designators do not have their own symbols. A symbol obtained for the expression x%re will be the symbol for x, and in this case x is allowed to be allocatable.

Fixes #166278.


Full diff: https://github.com/llvm/llvm-project/pull/166612.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-omp-atomic.cpp (+5-3)
  • (added) flang/test/Lower/OpenMP/atomic-update-capture-complex-part.f90 (+17)
diff --git a/flang/lib/Semantics/check-omp-atomic.cpp b/flang/lib/Semantics/check-omp-atomic.cpp
index 2707921ca1dfa..ec03e6fe2d920 100644
--- a/flang/lib/Semantics/check-omp-atomic.cpp
+++ b/flang/lib/Semantics/check-omp-atomic.cpp
@@ -590,9 +590,11 @@ void OmpStructureChecker::CheckAtomicVariable(
 
   CheckAtomicType(syms.back(), source, atom.AsFortran(), checkTypeOnPointer);
 
-  if (IsAllocatable(syms.back()) && !IsArrayElement(atom)) {
-    context_.Say(source, "Atomic variable %s cannot be ALLOCATABLE"_err_en_US,
-        atom.AsFortran());
+  if (!IsArrayElement(atom) && !ExtractComplexPart(atom)) {
+    if (IsAllocatable(syms.back())) {
+      context_.Say(source, "Atomic variable %s cannot be ALLOCATABLE"_err_en_US,
+          atom.AsFortran());
+    }
   }
 }
 
diff --git a/flang/test/Lower/OpenMP/atomic-update-capture-complex-part.f90 b/flang/test/Lower/OpenMP/atomic-update-capture-complex-part.f90
new file mode 100644
index 0000000000000..ee15b8805a69b
--- /dev/null
+++ b/flang/test/Lower/OpenMP/atomic-update-capture-complex-part.f90
@@ -0,0 +1,17 @@
+!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=60 %s -o - | FileCheck %s
+
+! Check that this compiles successfully.
+
+!CHECK: omp.atomic.capture
+!CHECK: omp.atomic.read
+!CHECK: omp.atomic.update
+subroutine f00
+  implicit none
+  real :: c
+  complex, allocatable :: x
+  !$omp atomic update capture
+    c = x%re
+    x%re = x%re + 1.0
+  !$omp end atomic
+end
+

@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2025

@llvm/pr-subscribers-flang-fir-hlfir

Author: Krzysztof Parzyszek (kparzysz)

Changes

Complex part designators do not have their own symbols. A symbol obtained for the expression x%re will be the symbol for x, and in this case x is allowed to be allocatable.

Fixes #166278.


Full diff: https://github.com/llvm/llvm-project/pull/166612.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-omp-atomic.cpp (+5-3)
  • (added) flang/test/Lower/OpenMP/atomic-update-capture-complex-part.f90 (+17)
diff --git a/flang/lib/Semantics/check-omp-atomic.cpp b/flang/lib/Semantics/check-omp-atomic.cpp
index 2707921ca1dfa..ec03e6fe2d920 100644
--- a/flang/lib/Semantics/check-omp-atomic.cpp
+++ b/flang/lib/Semantics/check-omp-atomic.cpp
@@ -590,9 +590,11 @@ void OmpStructureChecker::CheckAtomicVariable(
 
   CheckAtomicType(syms.back(), source, atom.AsFortran(), checkTypeOnPointer);
 
-  if (IsAllocatable(syms.back()) && !IsArrayElement(atom)) {
-    context_.Say(source, "Atomic variable %s cannot be ALLOCATABLE"_err_en_US,
-        atom.AsFortran());
+  if (!IsArrayElement(atom) && !ExtractComplexPart(atom)) {
+    if (IsAllocatable(syms.back())) {
+      context_.Say(source, "Atomic variable %s cannot be ALLOCATABLE"_err_en_US,
+          atom.AsFortran());
+    }
   }
 }
 
diff --git a/flang/test/Lower/OpenMP/atomic-update-capture-complex-part.f90 b/flang/test/Lower/OpenMP/atomic-update-capture-complex-part.f90
new file mode 100644
index 0000000000000..ee15b8805a69b
--- /dev/null
+++ b/flang/test/Lower/OpenMP/atomic-update-capture-complex-part.f90
@@ -0,0 +1,17 @@
+!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=60 %s -o - | FileCheck %s
+
+! Check that this compiles successfully.
+
+!CHECK: omp.atomic.capture
+!CHECK: omp.atomic.read
+!CHECK: omp.atomic.update
+subroutine f00
+  implicit none
+  real :: c
+  complex, allocatable :: x
+  !$omp atomic update capture
+    c = x%re
+    x%re = x%re + 1.0
+  !$omp end atomic
+end
+

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kparzysz kparzysz merged commit 89577e9 into main Nov 10, 2025
15 checks passed
@kparzysz kparzysz deleted the users/kparzysz/complex-allocatable-issue branch November 10, 2025 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:fir-hlfir flang:openmp flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flang][OpenMP] Incorrect compilation message for complex part designator of complex variable with ALLOCATABLE attribute within ATOMIC CAPTURE construct

4 participants