]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Fix up ICE in lower_omp_regimplify_operands_p [PR121977]
authorJakub Jelinek <jakub@redhat.com>
Thu, 18 Sep 2025 14:41:32 +0000 (16:41 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 18 Sep 2025 14:41:32 +0000 (16:41 +0200)
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.

gcc/omp-low.cc
gcc/testsuite/g++.dg/gomp/pr121977.C [new file with mode: 0644]

index 9d80a3573dce5e15d71745dd6fc76a9f9aee3877..6b0135ecdd971b2a45ed528ac945a8854f21e796 100644 (file)
@@ -14780,6 +14780,8 @@ lower_omp_regimplify_operands_p (tree *tp, int *walk_subtrees,
       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));
diff --git a/gcc/testsuite/g++.dg/gomp/pr121977.C b/gcc/testsuite/g++.dg/gomp/pr121977.C
new file mode 100644 (file)
index 0000000..223ea3c
--- /dev/null
@@ -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++;
+  }
+}