[flang-commits] [flang] [flang][openacc] Raise an error when UPDATE directive is in compute region (PR #217090)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Tue Aug 18 10:37:13 PDT 2026


https://github.com/clementval created https://github.com/llvm/llvm-project/pull/217090

This is in line with the reference compiler. 

>From e2348a3668b09c4fbdcf8f2b4f993a682a5e1837 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 18 Aug 2026 10:35:51 -0700
Subject: [PATCH] [flang][openacc] Raise an error when UPDATE directive is in
 compute region

---
 flang/lib/Semantics/check-acc-structure.cpp   |  2 +
 .../Semantics/OpenACC/acc-update-validity.f90 | 63 +++++++++++++++++++
 2 files changed, 65 insertions(+)

diff --git a/flang/lib/Semantics/check-acc-structure.cpp b/flang/lib/Semantics/check-acc-structure.cpp
index 84acf31aa4a58..25bc1de56120f 100644
--- a/flang/lib/Semantics/check-acc-structure.cpp
+++ b/flang/lib/Semantics/check-acc-structure.cpp
@@ -520,6 +520,8 @@ void AccStructureChecker::Leave(const parser::OpenACCStandaloneConstruct &x) {
     // Restriction - line 2669
     CheckOnlyAllowedAfter(llvm::acc::Clause::ACCC_device_type,
         updateOnlyAllowedAfterDeviceTypeClauses);
+    // An update directive may not appear within a compute construct.
+    CheckNotInComputeConstruct();
     break;
   case llvm::acc::Directive::ACCD_init:
   case llvm::acc::Directive::ACCD_shutdown:
diff --git a/flang/test/Semantics/OpenACC/acc-update-validity.f90 b/flang/test/Semantics/OpenACC/acc-update-validity.f90
index 8add56e81cf9e..3c7cfbdcdd158 100644
--- a/flang/test/Semantics/OpenACC/acc-update-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-update-validity.f90
@@ -64,4 +64,67 @@ program openacc_update_validity
   !ERROR: Clause IF is not allowed after clause DEVICE_TYPE on the UPDATE directive
   !$acc update device(i) device_type(*) if(.TRUE.)
 
+  !$acc parallel
+  !ERROR: Directive UPDATE may not be called within a compute region
+  !$acc update device(a)
+  !$acc end parallel
+
+  !$acc serial
+  !ERROR: Directive UPDATE may not be called within a compute region
+  !$acc update device(a)
+  !$acc end serial
+
+  !$acc kernels
+  !ERROR: Directive UPDATE may not be called within a compute region
+  !$acc update device(a)
+  !$acc end kernels
+
+  !$acc parallel
+  !$acc loop
+  do i = 1, N
+    !ERROR: Directive UPDATE may not be called within a compute region
+    !$acc update device(a)
+    a(i) = 3.14d0
+  end do
+  !$acc end parallel
+
+  !$acc serial
+  !$acc loop
+  do i = 1, N
+    !ERROR: Directive UPDATE may not be called within a compute region
+    !$acc update device(a)
+    a(i) = 3.14d0
+  end do
+  !$acc end serial
+
+  !$acc kernels
+  !$acc loop
+  do i = 1, N
+    !ERROR: Directive UPDATE may not be called within a compute region
+    !$acc update device(a)
+    a(i) = 3.14d0
+  end do
+  !$acc end kernels
+
+  !$acc parallel loop
+  do i = 1, N
+    !ERROR: Directive UPDATE may not be called within a compute region
+    !$acc update device(a)
+    a(i) = 3.14d0
+  end do
+
+  !$acc serial loop
+  do i = 1, N
+    !ERROR: Directive UPDATE may not be called within a compute region
+    !$acc update device(a)
+    a(i) = 3.14d0
+  end do
+
+  !$acc kernels loop
+  do i = 1, N
+    !ERROR: Directive UPDATE may not be called within a compute region
+    !$acc update device(a)
+    a(i) = 3.14d0
+  end do
+
 end program openacc_update_validity



More information about the flang-commits mailing list