[clang] 2667845 - [OpenACC] device_type on set should have only 1 architecture

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 10 14:49:17 PDT 2025


Author: erichkeane
Date: 2025-04-10T14:49:13-07:00
New Revision: 26678454847e7b76ff8947c50c93d203de4a15a0

URL: https://github.com/llvm/llvm-project/commit/26678454847e7b76ff8947c50c93d203de4a15a0
DIFF: https://github.com/llvm/llvm-project/commit/26678454847e7b76ff8947c50c93d203de4a15a0.diff

LOG: [OpenACC] device_type on set should have only 1 architecture

Discussions with the OpenACC Standard folks and the dialect folks showed
that the ability to have 'set' have a 'device_type' with more than one
architecture was a mistake, and one that will be fixed in future
revisions of the standard.  Since the dialect requires this anyway,
we'll implement this in advance of standardization.

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticSemaKinds.td
    clang/lib/Sema/SemaOpenACCClause.cpp
    clang/test/SemaOpenACC/set-construct.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fdf3f8816e746..3cb2731488fab 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -13063,6 +13063,9 @@ def err_acc_invalid_modifier
     : Error<"OpenACC '%0' modifier not valid on '%1' clause">;
 def err_acc_invalid_default_type
     : Error<"invalid value %0 in '%1' clause; valid values are %2">;
+def err_acc_device_type_multiple_archs
+    : Error<"OpenACC 'device_type' clause on a 'set' construct only permits "
+            "one architecture">;
 
 // AMDGCN builtins diagnostics
 def err_amdgcn_load_lds_size_invalid_value : Error<"invalid size value">;

diff  --git a/clang/lib/Sema/SemaOpenACCClause.cpp b/clang/lib/Sema/SemaOpenACCClause.cpp
index 8aa0c52f0ce19..ab25dcfd1a081 100644
--- a/clang/lib/Sema/SemaOpenACCClause.cpp
+++ b/clang/lib/Sema/SemaOpenACCClause.cpp
@@ -1338,6 +1338,16 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause(
       checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
     return nullptr;
 
+  // Based on discussions, having more than 1 'architecture' on a 'set' is
+  // nonsensical, so we're going to fix the standard to reflect this.  Implement
+  // the limitation, since the Dialect requires this.
+  if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Set &&
+      Clause.getDeviceTypeArchitectures().size() > 1) {
+    SemaRef.Diag(Clause.getDeviceTypeArchitectures()[1].second,
+                 diag::err_acc_device_type_multiple_archs);
+    return nullptr;
+  }
+
   // The list of valid device_type values. Flang also has these hardcoded in
   // openacc_parsers.cpp, as there does not seem to be a reliable backend
   // source. The list below is sourced from Flang, though NVC++ supports only

diff  --git a/clang/test/SemaOpenACC/set-construct.cpp b/clang/test/SemaOpenACC/set-construct.cpp
index 9a90ea67b1bd2..ac141d097532b 100644
--- a/clang/test/SemaOpenACC/set-construct.cpp
+++ b/clang/test/SemaOpenACC/set-construct.cpp
@@ -66,4 +66,12 @@ void uses() {
   // expected-error at +2{{'if' clause cannot appear more than once on a 'set' directive}}
   // expected-note at +1{{previous clause is here}}
 #pragma acc set device_type(acc_device_nvidia) if(true) if (true)
+
+  // expected-error at +2{{OpenACC 'device_type' clause on a 'set' construct only permits one architecture}}
+  // expected-error at +1{{OpenACC 'set' construct must have at least one 'default_async', 'device_num', 'device_type' or 'if' clause}}
+#pragma acc set device_type(nvidia, radeon)
+
+  // expected-error at +2{{OpenACC 'device_type' clause on a 'set' construct only permits one architecture}}
+  // expected-error at +1{{OpenACC 'set' construct must have at least one 'default_async', 'device_num', 'device_type' or 'if' clause}}
+#pragma acc set device_type(nonsense, nvidia, radeon)
 }


        


More information about the cfe-commits mailing list