The following testcase ICEs in functions called from
lower_omp_regimplify_operands_p, because maybe_lookup_decl returns
NULL for this (on the outer taskloop context) when regimplifying the
taskloop pre body. If it isn't found in current context, we should
look in outer ones.
2025-09-18 Jakub Jelinek <jakub@redhat.com>
PR c++/121977
* omp-low.cc (lower_omp_regimplify_operands_p): If maybe_lookup_decl
returns NULL, use maybe_lookup_decl_in_outer_ctx as fallback.
* g++.dg/gomp/pr121977.C: New test.
lower_omp_regimplify_operands_data *ldata
= (lower_omp_regimplify_operands_data *) wi->info;
tree o = maybe_lookup_decl (t, ldata->ctx);
+ if (o == NULL_TREE)
+ o = maybe_lookup_decl_in_outer_ctx (t, ldata->ctx);
if (o != t)
{
ldata->decls->safe_push (DECL_VALUE_EXPR (*tp));
--- /dev/null
+// PR c++/121977
+// { dg-do compile }
+// { dg-additional-options "-ftrivial-auto-var-init=zero" }
+
+struct T { T () {}; virtual ~T () {}; int t; };
+struct S : virtual public T { int a; void foo (); };
+
+void
+S::foo ()
+{
+#pragma omp parallel
+ {
+ #pragma omp taskloop firstprivate (a, t) lastprivate (t)
+ for (int i = 0; i < a; i++)
+ t++;
+ }
+}