[flang-commits] [flang] [flang][openacc] Allow scalar in acc cache directive (PR #70713)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Mon Oct 30 12:57:55 PDT 2023


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

None

>From 5fd2cf8999b0aaf72a07807e6c44ec2c43c02280 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Mon, 30 Oct 2023 12:55:36 -0700
Subject: [PATCH] [flang][openacc] Allow scalar in acc cache directive

---
 flang/docs/OpenACC.md                               | 1 +
 flang/lib/Semantics/resolve-directives.cpp          | 5 ++++-
 flang/test/Semantics/OpenACC/acc-cache-validity.f90 | 8 ++------
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/flang/docs/OpenACC.md b/flang/docs/OpenACC.md
index 41c974f837421b9..4c36a38f8bf5731 100644
--- a/flang/docs/OpenACC.md
+++ b/flang/docs/OpenACC.md
@@ -24,3 +24,4 @@ local:
 * The `if` clause accepts scalar integer expression in addition to scalar
   logical expression.
 * `!$acc routine` directive can be placed at the top level. 
+* `!$acc cache` directive accepts scalar variable.
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 66d3a9da3650579..fc0648b34bedef9 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1052,7 +1052,10 @@ static bool IsLastNameArray(const parser::Designator &designator) {
   const evaluate::DataRef dataRef{*(name.symbol)};
   return common::visit(
       common::visitors{
-          [](const evaluate::SymbolRef &ref) { return ref->Rank() > 0; },
+          [](const evaluate::SymbolRef &ref) {
+            return ref->Rank() > 0 ||
+                ref->GetType()->category() == DeclTypeSpec::Numeric;
+          },
           [](const evaluate::ArrayRef &aref) {
             return aref.base().IsSymbol() ||
                 aref.base().GetComponent().base().Rank() == 0;
diff --git a/flang/test/Semantics/OpenACC/acc-cache-validity.f90 b/flang/test/Semantics/OpenACC/acc-cache-validity.f90
index 9eb12b9e2b7e4d4..49f400e763bfb53 100644
--- a/flang/test/Semantics/OpenACC/acc-cache-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-cache-validity.f90
@@ -29,15 +29,11 @@ program openacc_cache_validity
   !$acc cache(t%arr)
   !$acc cache(ta(1:2)%arr)
   !$acc cache(ta(1:2)%arr(1:4))
-
-  !ERROR: Only array element or subarray are allowed in CACHE directive
-  !$acc cache(ta(1:2)%s)
-
-  !ERROR: Only array element or subarray are allowed in CACHE directive
   !$acc cache(i)
+  !$acc cache(t%s)
 
   !ERROR: Only array element or subarray are allowed in CACHE directive
-  !$acc cache(t%s)
+  !$acc cache(t)
 
   !ERROR: Only array element or subarray are allowed in CACHE directive
   !$acc cache(/i/)



More information about the flang-commits mailing list