From: Patrick Palka Date: Tue, 14 Apr 2026 19:36:54 +0000 (-0400) Subject: c++: reference to static local meta::info as targ [PR124824] X-Git-Tag: basepoints/gcc-17~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0943fcaca7dd3415546f68397c24e38afaffaf3d;p=thirdparty%2Fgcc.git c++: reference to static local meta::info as targ [PR124824] Here we're crashing in discriminator_for_local_entity during mangling of f<&M>() because determine_local_discriminator is never called for the static local meta::info M. The relevant code path in cp_finish_decl was disabled for consteval-only types in the main Reflection commit r16-6808 to avoid creating a varpool_node for such types. This patch naively fixes this by moving the consteval_only_p check so that we still call determine_local_discriminator for such types. PR c++/124824 gcc/cp/ChangeLog: * decl.cc (cp_finish_decl): Sink !consteval_only_p check to only guard the varpool_node::get_create call. gcc/testsuite/ChangeLog: * g++.dg/reflect/mangle6.C: New test. Reviewed-by: Jason Merrill --- diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index ecdefe300d5..7e40226d739 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -9885,8 +9885,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, variable. */ if (DECL_FUNCTION_SCOPE_P (decl) && TREE_STATIC (decl) - && !DECL_ARTIFICIAL (decl) - && !consteval_only_p (decl)) + && !DECL_ARTIFICIAL (decl)) { /* The variable holding an anonymous union will have had its discriminator set in finish_anon_union, after which it's @@ -9904,9 +9903,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, walk_tree (&init, notice_forced_label_r, NULL, NULL); add_local_decl (cfun, decl); } - /* And make sure it's in the symbol table for - c_parse_final_cleanups to find. */ - varpool_node::get_create (decl); + if (!consteval_only_p (decl)) + /* And make sure it's in the symbol table for + c_parse_final_cleanups to find. */ + varpool_node::get_create (decl); } if (flag_openmp diff --git a/gcc/testsuite/g++.dg/reflect/mangle6.C b/gcc/testsuite/g++.dg/reflect/mangle6.C new file mode 100644 index 00000000000..23030f77e4c --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/mangle6.C @@ -0,0 +1,19 @@ +// PR c++/124824 +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } + +template void f() { } + +int main() { + { + static constexpr auto M = ^^int; + f<&M>(); + } + { + static constexpr auto M = ^^int; + f<&M>(); + } +} + +// { dg-final { scan-assembler "_Z1fITnDaXadL_ZZ4mainE1MEEEvv" } } +// { dg-final { scan-assembler "_Z1fITnDaXadL_ZZ4mainE1M_0EEEvv" } }