[flang-commits] [flang] [flang][OpenACC] Fix crash on invalid clauses in WAIT and ATOMIC constructs (PR #187263)
via flang-commits
flang-commits at lists.llvm.org
Wed Mar 18 05:51:52 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-openacc
Author: Zeyi Xu (zeyi2)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/187263.diff
3 Files Affected:
- (modified) flang/lib/Semantics/resolve-directives.cpp (+18)
- (modified) flang/test/Semantics/OpenACC/acc-atomic-validity.f90 (+5-1)
- (modified) flang/test/Semantics/OpenACC/acc-wait-validity.f90 (+3)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/187263
More information about the flang-commits
mailing list