[clang] [Clang][OpenMP][NFC] Add test for `class-type` data members as loop counters (PR #228831)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 3 23:52:40 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Akash Manna (akash-manna-sky)
<details>
<summary>Changes</summary>
Fixes #<!-- -->140243
An OpenMP loop whose init assigns to a data member of class type, like `for (a = x; ...)` with `I<int> a`, crashed in `OpenMPIterationSpaceChecker::checkAndSetInit`. Such an assignment is an `operator=` call, so it goes through the `CXXOperatorCallExpr` branch, and two of the `setLCDeclAndLB` calls there took the bound from `BO`, the `BinaryOperator` cast that had already failed and is null at that point. The invalid code in the report is not needed: a valid loop over an iterator-typed data member crashed the same way.
#<!-- -->203252 replaced those `BO->getRHS()` uses with `CE->getArg(1)` as part of another fix, so the crash is gone on trunk and no source change is needed. This PR only adds a regression test so the issue can be closed.
---
Full diff: https://github.com/llvm/llvm-project/pull/228831.diff
1 Files Affected:
- (modified) clang/test/OpenMP/parallel_for_loop_messages.cpp (+39)
``````````diff
diff --git a/clang/test/OpenMP/parallel_for_loop_messages.cpp b/clang/test/OpenMP/parallel_for_loop_messages.cpp
index 0b755f7411748..644dfed66cc79 100644
--- a/clang/test/OpenMP/parallel_for_loop_messages.cpp
+++ b/clang/test/OpenMP/parallel_for_loop_messages.cpp
@@ -629,3 +629,42 @@ void test_loop_firstprivate_lastprivate() {
for (int i = 0; i < 16; ++i)
;
}
+
+namespace GH140243 {
+template <typename T>
+class I { };
+struct R { R () {}; ~R () {}; I<int> r; };
+struct T { T () {}; virtual ~T () {}; I<int> t; };
+// expected-note at +1 {{A defined here}}
+struct A : public R, virtual public T { A () {} I<int> a; void m1 (const I<int> &, const I<int> &); };
+
+// expected-error at +1 {{out-of-line definition of 'm1' does not match any declaration in 'GH140243::A'}}
+void A::m1 (const I<int> &x)
+{
+ int w = 0;
+// expected-error at +5 {{invalid operands to binary expression ('I<int>' and 'int')}}
+// expected-error at +4 {{cannot increment value of type 'I<int>'}}
+// expected-error at +3 {{condition of OpenMP for loop must be a relational comparison}}
+// expected-error at +2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'a'}}
+ #pragma omp parallel for reduction(|:w)
+ for (a = x; A::a < 10; a++)
+ w |= (1 << *A::a); // expected-error {{indirection requires pointer operand ('I<int>' invalid)}}
+}
+
+struct B {
+ GoodIter it;
+ void m1(GoodIter begin, GoodIter end);
+};
+
+void B::m1(GoodIter begin, GoodIter end) {
+#pragma omp parallel for
+ for (it = begin; it < end; ++it)
+ ;
+#pragma omp parallel for
+ for (this->it = begin; B::it < end; ++B::it)
+ ;
+#pragma omp parallel for private(it)
+ for (it = begin; it < end; ++it)
+ ;
+}
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/228831
More information about the cfe-commits
mailing list