Hi!

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.

Tested on x86_64-linux, committed to trunk (for now).

2025-09-18  Jakub Jelinek  <[email protected]>

        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.

--- gcc/omp-low.cc.jj   2025-08-06 10:41:32.000000000 +0200
+++ gcc/omp-low.cc      2025-09-18 15:30:35.833767371 +0200
@@ -14780,6 +14780,8 @@ lower_omp_regimplify_operands_p (tree *t
       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));
--- gcc/testsuite/g++.dg/gomp/pr121977.C.jj     2025-09-18 15:36:15.094200682 
+0200
+++ gcc/testsuite/g++.dg/gomp/pr121977.C        2025-09-18 15:35:53.633489559 
+0200
@@ -0,0 +1,17 @@
+// 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++;
+  }
+}

        Jakub

Reply via email to