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

via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 17 10:07:35 PDT 2026


Author: Erich Keane
Date: 2026-04-17T10:07:31-07:00
New Revision: 0fd21b102286f3a920950d650cb50420b0f94fc3

URL: https://github.com/llvm/llvm-project/commit/0fd21b102286f3a920950d650cb50420b0f94fc3
DIFF: https://github.com/llvm/llvm-project/commit/0fd21b102286f3a920950d650cb50420b0f94fc3.diff

LOG: [OpenACC] Require a complete type for vars-with-restrictions (#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

Added: 
    

Modified: 
    clang/lib/Sema/SemaOpenACC.cpp
    clang/test/SemaOpenACC/compute-construct-firstprivate-clause.cpp
    clang/test/SemaOpenACC/compute-construct-private-clause.cpp
    clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp

Removed: 
    


################################################################################
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