]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/reflection: fix ICE with OMP_CLAUSE [PR124227]
authorMarek Polacek <polacek@redhat.com>
Tue, 24 Feb 2026 13:55:31 +0000 (08:55 -0500)
committerMarek Polacek <polacek@redhat.com>
Wed, 25 Feb 2026 13:30:19 +0000 (08:30 -0500)
This test crashes with -fopenmp -freflection because consteval_only_p
gets

  <omp_clause 0x7fffe99db120
    type <tree_vec 0x7fffe982b900 length:3>
    reduction
    op-0: <var_decl 0x7fffe99d6390 acc>
    op-1: <init_expr 0x7fffe99c9870>
    op-2: <bind_expr 0x7fffe982b8a0>
    op-3: <var_decl 0x7fffe99d6428 D.2864>
    op-4:>

so it takes its type, but complete_type crashes on a TREE_VEC.

So let's handle TREE_VEC in consteval_only_p.

PR c++/124227

gcc/cp/ChangeLog:

* reflect.cc (consteval_only_p): Handle TREE_VEC.

gcc/testsuite/ChangeLog:

* g++.dg/reflect/pr124227.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/reflect.cc
gcc/testsuite/g++.dg/reflect/pr124227.C [new file with mode: 0644]

index 522b7c06a293c983f797889014fd0224ba3bc174..5254ac028d1b8e14b54a757e7530d322876c17f9 100644 (file)
@@ -8086,6 +8086,14 @@ consteval_only_p (tree t)
   if (!t)
     return false;
 
+  if (TREE_CODE (t) == TREE_VEC)
+    {
+      for (tree arg : tree_vec_range (t))
+       if (arg && consteval_only_p (arg))
+         return true;
+      return false;
+    }
+
   /* We need the complete type otherwise we'd have no fields for class
      templates and thus come up with zilch for things like
        template<typename T>
diff --git a/gcc/testsuite/g++.dg/reflect/pr124227.C b/gcc/testsuite/g++.dg/reflect/pr124227.C
new file mode 100644 (file)
index 0000000..09e1404
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/124227
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection -fopenmp" }
+// { dg-require-effective-target fopenmp }
+
+using b = float;
+template <typename> class c {};
+#pragma omp declare reduction(d : c<float> : omp_in)
+auto e = [] {
+c<b> acc;
+#pragma omp parallel reduction(d : acc)
+{
+}
+};
+