[flang-commits] [flang] [flang][OpenACC] Fix crash on invalid clauses in WAIT and ATOMIC constructs (PR #187263)
Zeyi Xu via flang-commits
flang-commits at lists.llvm.org
Wed Mar 18 05:51:16 PDT 2026
https://github.com/zeyi2 created https://github.com/llvm/llvm-project/pull/187263
None
>From 8c77c71b14304f993d1669645f55251f75ee2af4 Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Wed, 18 Mar 2026 20:50:59 +0800
Subject: [PATCH] [flang][OpenACC] Fix crash on invalid clauses in WAIT and
ATOMIC constructs
---
flang/lib/Semantics/resolve-directives.cpp | 18 ++++++++++++++++++
.../Semantics/OpenACC/acc-atomic-validity.f90 | 6 +++++-
.../Semantics/OpenACC/acc-wait-validity.f90 | 3 +++
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index c8ffa22d6bb5f..f9e31b259db0d 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -239,6 +239,11 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
GetContext().withinConstruct = true;
}
+ bool Pre(const parser::OpenACCWaitConstruct &);
+ void Post(const parser::OpenACCWaitConstruct &) { PopContext(); }
+ bool Pre(const parser::OpenACCAtomicConstruct &);
+ void Post(const parser::OpenACCAtomicConstruct &) { PopContext(); }
+
bool Pre(const parser::OpenACCCacheConstruct &);
void Post(const parser::OpenACCCacheConstruct &) { PopContext(); }
@@ -1620,6 +1625,19 @@ void AccAttributeVisitor::AllowOnlyVariable(const parser::AccObject &object) {
object.u);
}
+bool AccAttributeVisitor::Pre(const parser::OpenACCWaitConstruct &x) {
+ const auto &verbatim{std::get<parser::Verbatim>(x.t)};
+ PushContext(verbatim.source, llvm::acc::Directive::ACCD_wait);
+ ClearDataSharingAttributeObjects();
+ return true;
+}
+
+bool AccAttributeVisitor::Pre(const parser::OpenACCAtomicConstruct &x) {
+ PushContext(x.source, llvm::acc::Directive::ACCD_atomic);
+ ClearDataSharingAttributeObjects();
+ return true;
+}
+
bool AccAttributeVisitor::Pre(const parser::OpenACCCacheConstruct &x) {
const auto &verbatim{std::get<parser::Verbatim>(x.t)};
PushContext(verbatim.source, llvm::acc::Directive::ACCD_cache);
diff --git a/flang/test/Semantics/OpenACC/acc-atomic-validity.f90 b/flang/test/Semantics/OpenACC/acc-atomic-validity.f90
index 9f8450456586c..a833ee987f48f 100644
--- a/flang/test/Semantics/OpenACC/acc-atomic-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-atomic-validity.f90
@@ -105,6 +105,10 @@ program openacc_atomic_validity
!$acc end parallel
+ !ERROR: COPY clause is not allowed on the ATOMIC UPDATE COPY(I)
+ !$acc atomic update copy(i)
+ c(i) = c(i) + 1
+
end program openacc_atomic_validity
subroutine capture_with_convert_f64_to_i32()
@@ -147,4 +151,4 @@ subroutine capture_with_convert_f64_to_i32()
v = x
x = w * w
!$acc end atomic
-end subroutine capture_with_convert_f64_to_i32
\ No newline at end of file
+end subroutine capture_with_convert_f64_to_i32
diff --git a/flang/test/Semantics/OpenACC/acc-wait-validity.f90 b/flang/test/Semantics/OpenACC/acc-wait-validity.f90
index 25d603dad0502..c226751ce8b69 100644
--- a/flang/test/Semantics/OpenACC/acc-wait-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-wait-validity.f90
@@ -39,4 +39,7 @@ program openacc_wait_validity
!ERROR: At most one ASYNC clause can appear on the WAIT directive
!$acc wait(1) if(.true.) async(1) async
+ !ERROR: COPY clause is not allowed on the WAIT directive
+ !$acc wait copy(ifCondition)
+
end program openacc_wait_validity
More information about the flang-commits
mailing list