On 1/18/26 11:31 AM, Nathaniel Shead wrote:
On Sat, Jan 17, 2026 at 09:36:23PM +0800, Jason Merrill wrote:
On 1/17/26 8:49 PM, Nathaniel Shead wrote:
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?
I'm not sure if this is really the best approach in the end but should
fix the errors at least.
-- >8 --
The failure in the given PR occurs because when setting up an
imported vague-linkage variable, we currently call 'maybe_commonize_var'
which for -freflection checks 'consteval_only_p'. Unfortunately this
latter function needs to call 'complete_type_p' which can perform
recursive loading of the (possibly yet-to-be-streamed) class type,
breaking modules assumptions.
Can we just drop the consteval_only_p check in maybe_commonize_var?
I'd tried that initially but that crashes in e.g. reflect/expr10.C:
#0 fancy_abort (file=0x43b6f87 "../../gcc/gcc/cp/mangle.cc", line=2316,
function=0x43b7428 "discriminator_for_local_entity") at
../../gcc/gcc/diagnostics/context.cc:1772
#1 0x00000000011dcdb7 in discriminator_for_local_entity (entity=<var_decl
0x7ffff75c2558 gl>) at ../../gcc/gcc/cp/mangle.cc:2316
#2 0x00000000011dd744 in write_local_name (function=<function_decl 0x7ffff75b6900
operator()>, local_entity=<var_decl 0x7ffff75c2558 gl>, entity=<var_decl
0x7ffff75c2558 gl>)
at ../../gcc/gcc/cp/mangle.cc:2415
#3 0x00000000011d59d0 in write_name (decl=<var_decl 0x7ffff75c2558 gl>,
ignore_local_scope=0) at ../../gcc/gcc/cp/mangle.cc:1166
#4 0x00000000011d426a in write_encoding (decl=<var_decl 0x7ffff75c2558 gl>) at
../../gcc/gcc/cp/mangle.cc:939
#5 0x00000000011d3783 in write_mangled_name (decl=<var_decl 0x7ffff75c2558
gl>, top_level=true) at ../../gcc/gcc/cp/mangle.cc:821
#6 0x00000000011ea556 in mangle_decl_string (decl=<var_decl 0x7ffff75c2558
gl>) at ../../gcc/gcc/cp/mangle.cc:4716
#7 0x00000000011ea5b3 in get_mangled_id (decl=<var_decl 0x7ffff75c2558 gl>) at
../../gcc/gcc/cp/mangle.cc:4732
#8 0x00000000011ea904 in mangle_decl (decl=<var_decl 0x7ffff75c2558 gl>) at
../../gcc/gcc/cp/mangle.cc:4770
#9 0x00000000023a6fe4 in decl_assembler_name (decl=<var_decl 0x7ffff75c2558
gl>) at ../../gcc/gcc/tree.cc:856
#10 0x0000000001711d88 in symtab_node::get_comdat_group_id (this=<symtab_node * const
0x7ffff7421400 "gl"/3>) at ../../gcc/gcc/cgraph.h:289
#11 0x00000000017361f2 in analyze_functions (first_time=true) at
../../gcc/gcc/cgraphunit.cc:1219
#12 0x0000000001739c11 in symbol_table::finalize_compilation_unit
(this=0x7ffff7406000) at ../../gcc/gcc/cgraphunit.cc:2590
#13 0x0000000001f1e5a8 in compile_file () at ../../gcc/gcc/toplev.cc:482
#14 0x0000000001f21c85 in do_compile () at ../../gcc/gcc/toplev.cc:2225
#15 0x0000000001f22135 in toplev::main (this=0x7fffffffd612, argc=26,
argv=0x7fffffffd758) at ../../gcc/gcc/toplev.cc:2390
#16 0x0000000003ecf9d9 in main (argc=26, argv=0x7fffffffd758) at
../../gcc/gcc/main.cc:39
The issue appears to be that because we give the variable a
comdat group we then attempt to mangle it at finalisation time, which
crashes. Perhaps we could move the check out to all callers of
'maybe_commonize_var' instead but I don't think that's a great choice
either.
This seems to avoid that while also fixing the testcase; I haven't done
any other testing.
From eb72e0b8c9d92417542e6488896f500304c55ca2 Mon Sep 17 00:00:00 2001
From: Jason Merrill <[email protected]>
Date: Wed, 28 Jan 2026 14:17:13 +0800
Subject: [PATCH] c++: defer DECL_ONE_ONLY vs consteval-only
To: [email protected]
gcc/cp/ChangeLog:
* decl.cc (maybe_commonize_var): Don't check consteval_only_p.
(make_rtl_for_nonlocal_decl): Undo make_decl_one_only for
consteval-only variables.
---
gcc/cp/decl.cc | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 270158510df..2671e461872 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -7263,10 +7263,6 @@ maybe_commonize_var (tree decl)
if (DECL_ARTIFICIAL (decl) && !DECL_DECOMPOSITION_P (decl))
return;
- /* These are not output at all. */
- if (consteval_only_p (decl))
- return;
-
/* Static data in a function with comdat linkage also has comdat
linkage. */
if ((TREE_STATIC (decl)
@@ -8758,6 +8754,14 @@ make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
{
/* Disable assemble_variable. */
DECL_EXTERNAL (decl) = true;
+ /* Undo make_decl_one_only. */
+ if (DECL_COMDAT_GROUP (decl))
+ {
+ DECL_COMDAT (decl) = false;
+ symtab_node *node = symtab_node::get (decl);
+ node->set_comdat_group (NULL);
+ node->dissolve_same_comdat_group_list ();
+ }
return;
}
--
2.52.0