c++, dwarf2out: Debug info for namespace scope structured bindings [PR122968]
As the following testcase shows, we weren't emitting any debug info for
namespace scope structured bindings (except for tuple based ones, those
worked fine).
There are multiple problems:
1) for tuple based structured bindings there is cp_finish_decl and the
VAR_DECLs are registered in varpool, but the other ones are just
VAR_DECLs with DECL_VALUE_EXPR for elements of the underlying VAR_DECL,
so they don't really appear in the IL; and we weren't calling
early_global_decl debug hook on those
2) fixing that makes those appear only with -fno-eliminate-unused-symbols,
because whether something is used is determined by the presence of
varpool node for it; I think varpool is unprepared to handle
DECL_VALUE_EXPR VAR_DECLs, those would appear always unused;
so, the patch instead adds mapping from the underlying VAR_DECL
to the structured bindings needed for debug info in an artificial
attribute and when marking the underlying VAR_DECL of a structured
binding as used, it marks all the structured bindings attached to it
as well
3) with this, the DW_TAG_variable DIEs for structured bindings appear even
without -fno-eliminate-unused-symbols, but they still don't have
locations; for that we need to arrange when we add DW_AT_location to the
underlying variable to also add DW_AT_location to the structured bindings
afterwards
Note, this patch doesn't improve the structured bindings bound to bitfields
case the PR was filed for originally, neither at namespace scope nor at
block scope. That will need to be handled incrementally.
2025-12-19 Jakub Jelinek <jakub@redhat.com>
PR debug/122968
gcc/
* dwarf2out.cc (premark_used_variables): Handle "structured bindings"
attribute.
(dwarf2out_late_global_decl): Likewise.
gcc/cp/
* decl.cc (cp_finish_decomp): For structured bindings at namespace
scope which have DECL_HAS_VALUE_EXPR_P set, call early_global_decl
debug hook and put all such structured bindings into
"structured bindings" attribute arguments on the underlying decl.
gcc/testsuite/
* g++.dg/guality/decomp1.C: New test.