[clang] [OpenACC] Require a complete type for vars-with-restrictions (PR #192680)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 17 08:09:03 PDT 2026


https://github.com/erichkeane created https://github.com/llvm/llvm-project/pull/192680

The bug report shows a case where an incomplete type was passed to a var-list in a clause that has a restriction.  Only the 'private',
  'firstprivate', and 'reduction' clauses have such restrictions on what
  they can reference, so only those will cause problems.

This patch adds a 'completeness' requirement for all 3 of those to make sure we can properly enforce our restrictions.

Fixes: #192664

>From f6492e12c1dc5976f2d3b71533c3c20d95a375bb Mon Sep 17 00:00:00 2001
From: erichkeane <ekeane at nvidia.com>
Date: Fri, 17 Apr 2026 08:06:58 -0700
Subject: [PATCH] [OpenACC] Require a complete type for vars-with-restrictions

The bug report shows a case where an incomplete type was passed to a
var-list in a clause that has a restriction.  Only the 'private',
  'firstprivate', and 'reduction' clauses have such restrictions on what
  they can reference, so only those will cause problems.

This patch adds a 'completeness' requirement for all 3 of those to make
sure we can properly enforce our restrictions.

Fixes: #192664
---
 clang/lib/Sema/SemaOpenACC.cpp                           | 5 +++++
 .../compute-construct-firstprivate-clause.cpp            | 9 +++++++++
 .../SemaOpenACC/compute-construct-private-clause.cpp     | 8 +++++++-
 .../SemaOpenACC/compute-construct-reduction-clause.cpp   | 9 +++++++++
 4 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 28c46dcccc9ea..1e71593dc76fe 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -659,6 +659,11 @@ ExprResult CheckVarType(SemaOpenACC &S, OpenACCClauseKind CK, Expr *VarExpr,
     return CheckVarType(S, CK, VarExpr, InnerLoc, ArrTy->getElementType());
   }
 
+  if (S.SemaRef.RequireCompleteType(InnerLoc, InnerTy,
+                                    Sema::CompleteTypeKind::Normal,
+                                    diag::err_incomplete_type))
+    return ExprError();
+
   auto *RD = InnerTy->getAsCXXRecordDecl();
 
   // if this isn't a C++ record decl, we can create/copy/destroy this thing at
diff --git a/clang/test/SemaOpenACC/compute-construct-firstprivate-clause.cpp b/clang/test/SemaOpenACC/compute-construct-firstprivate-clause.cpp
index eab8629904eb5..0e4fc6fa6b18c 100644
--- a/clang/test/SemaOpenACC/compute-construct-firstprivate-clause.cpp
+++ b/clang/test/SemaOpenACC/compute-construct-firstprivate-clause.cpp
@@ -110,3 +110,12 @@ void Inst() {
   TemplUses(i, Arr, C); // #TEMPL_USES_INST
   NTTP<5, NTTP_REFed>(); // #NTTP_INST
 }
+
+struct Incomplete;
+
+void incomplete_use(Incomplete &i) {
+  // expected-error at +2{{incomplete type 'Incomplete' where a complete type is required}}
+  // expected-note at -4{{forward declaration}}
+#pragma acc parallel firstprivate(i)
+  while (1);
+}
diff --git a/clang/test/SemaOpenACC/compute-construct-private-clause.cpp b/clang/test/SemaOpenACC/compute-construct-private-clause.cpp
index 88f0a684730c5..b42422888e655 100644
--- a/clang/test/SemaOpenACC/compute-construct-private-clause.cpp
+++ b/clang/test/SemaOpenACC/compute-construct-private-clause.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -fopenacc -verify
 
-struct Incomplete;
+struct Incomplete; // #INCOMPLETE
 enum SomeE{};
 typedef struct IsComplete {
   struct S { int A; } CompositeMember;
@@ -172,3 +172,9 @@ void inst_crash() {
   ThisCrashed<int>(1, 2);
 }
 
+void incomplete_use(Incomplete &i) {
+  // expected-error at +2{{incomplete type 'Incomplete' where a complete type is required}}
+  // expected-note@#INCOMPLETE{{forward declaration}}
+#pragma acc parallel private(i)
+  while (1);
+}
diff --git a/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp b/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp
index 70dc3d6d88937..0ef733b728d09 100644
--- a/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp
+++ b/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp
@@ -311,3 +311,12 @@ void inst() {
   // expected-note at +1{{in instantiation of function template specialization}}
   TemplUses(5, CoS, ChC);
 }
+
+struct Incomplete;
+
+void incomplete_use(Incomplete &i) {
+  // expected-error at +2{{incomplete type 'Incomplete' where a complete type is required}}
+  // expected-note at -4{{forward declaration}}
+#pragma acc parallel reduction(+:i)
+  while (1);
+}



More information about the cfe-commits mailing list