[clang] [OpenACC] Fix iterator-type lookup when kind is incomplete (PR #240424)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 9 07:51:05 PST 2026
https://github.com/erichkeane created https://github.com/llvm/llvm-project/pull/240424
OpenACC loop needs to have a random access iterator, and does some heroics to look into the 'iterator_category' to check for this. It ALSO checks whether the type referred to in the iterator_category inherits from std::random_access_iterator.
However, it was failing to make sure it was a definition before checked for base classes, leading to an assert.
This patch adds that check, which will make a iterator category incomplete type not attempt to check the 'base' class.
Fixes: #239962
>From 067aa10f086375033c8c084eeacbc2907ba4c677 Mon Sep 17 00:00:00 2001
From: erichkeane <ekeane at nvidia.com>
Date: Mon, 9 Nov 2026 07:37:21 -0800
Subject: [PATCH] [OpenACC] Fix iterator-type lookup when kind is incomplete
OpenACC loop needs to have a random access iterator, and does some
heroics to look into the 'iterator_category' to check for this. It ALSO
checks whether the type referred to in the iterator_category inherits
from std::random_access_iterator.
However, it was failing to make sure it was a definition before checked
for base classes, leading to an assert.
This patch adds that check, which will make a iterator category
incomplete type not attempt to check the 'base' class.
Fixes: #239962
---
clang/lib/Sema/SemaOpenACC.cpp | 7 +++---
clang/test/SemaOpenACC/combined-construct.cpp | 22 +++++++++++++++++++
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 65336f03122f1a..8eb850f509c6b5 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -1224,9 +1224,10 @@ bool isValidLoopVariableType(QualType LoopVarTy) {
// We can also support tag-types inherited from the
// random_access_iterator_tag.
- for (CXXBaseSpecifier BS : ItrCategoryDecl->bases())
- if (IsRandomAccessIteratorTag(BS.getType()->getAsCXXRecordDecl()))
- return true;
+ if (ItrCategoryDecl->isCompleteDefinition())
+ for (CXXBaseSpecifier BS : ItrCategoryDecl->bases())
+ if (IsRandomAccessIteratorTag(BS.getType()->getAsCXXRecordDecl()))
+ return true;
return false;
}
diff --git a/clang/test/SemaOpenACC/combined-construct.cpp b/clang/test/SemaOpenACC/combined-construct.cpp
index e7ca0eec583375..11fa2bbbeffb50 100644
--- a/clang/test/SemaOpenACC/combined-construct.cpp
+++ b/clang/test/SemaOpenACC/combined-construct.cpp
@@ -40,6 +40,10 @@ struct HasRAIteratorCollection {
SomeRAIterator &end();
};
+struct IncompleteIteratorCategory {
+ using iterator_category = struct Incomplete;
+};
+
void func_call();
template<typename Int, typename IntPtr, typename Float, typename Struct, typename Iterator, typename RandAccessIterator>
@@ -137,6 +141,15 @@ void SeqLoopRules() {
#pragma acc serial loop seq
for(f = 0;;f+=1);
+
+#pragma acc loop
+ // expected-error at +6{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'IncompleteIteratorCategory')}}
+ // expected-note at -2{{'loop' construct is here}}
+ // expected-error at +4{{OpenACC 'loop' construct must have a terminating condition}}
+ // expected-note at -4{{'loop' construct is here}}
+ // expected-error at +2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
+ // expected-note at -6{{'loop' construct is here}}
+ for (IncompleteIteratorCategory iic ;;);
}
@@ -382,6 +395,15 @@ void LoopRules() {
#pragma acc parallel loop
for(f = 0;f != end;f+=1);
+
+#pragma acc loop
+ // expected-error at +6{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'IncompleteIteratorCategory')}}
+ // expected-note at -2{{'loop' construct is here}}
+ // expected-error at +4{{OpenACC 'loop' construct must have a terminating condition}}
+ // expected-note at -4{{'loop' construct is here}}
+ // expected-error at +2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
+ // expected-note at -6{{'loop' construct is here}}
+ for (IncompleteIteratorCategory iic;;);
}
void inst() {
More information about the cfe-commits
mailing list