Author: Akash Manna Date: 2026-10-04T13:13:27Z New Revision: 8b0127c14e18f5856afbc2cc61461e2ab7e67609
URL: https://github.com/llvm/llvm-project/commit/8b0127c14e18f5856afbc2cc61461e2ab7e67609 DIFF: https://github.com/llvm/llvm-project/commit/8b0127c14e18f5856afbc2cc61461e2ab7e67609.diff LOG: [Clang][OpenMP][NFC] Add test for `class-type` data members as loop counters (#228831) 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. Added: Modified: clang/test/OpenMP/parallel_for_loop_messages.cpp Removed: ################################################################################ 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@+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@+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@+5 {{invalid operands to binary expression ('I<int>' and 'int')}} +// expected-error@+4 {{cannot increment value of type 'I<int>'}} +// expected-error@+3 {{condition of OpenMP for loop must be a relational comparison}} +// expected-error@+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) + ; +} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
