https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122968

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
As for the namespace scope non-tuple-based structured bindings, partial fix is
--- gcc/cp/decl.cc.jj   2025-12-02 14:36:42.774808436 +0100
+++ gcc/cp/decl.cc      2025-12-03 13:54:51.447330421 +0100
@@ -11092,6 +11092,11 @@ cp_finish_decomp (tree decl, cp_decomp *
            DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
          }
     }
+  else if (DECL_NAMESPACE_SCOPE_P (decl) && !seen_error ())
+    for (unsigned int i = 0; i < count; i++)
+      if ((unsigned) pack != i
+         && DECL_HAS_VALUE_EXPR_P (v[i]))
+       (*debug_hooks->early_global_decl) (v[i]);
   return false;
 }

--- gcc/testsuite/g++.dg/guality/decomp1.C.jj   2025-12-03 14:26:09.276912777
+0100
+++ gcc/testsuite/g++.dg/guality/decomp1.C      2025-12-03 14:01:21.561593627
+0100
@@ -0,0 +1,15 @@
+// PR debug/122968
+// { dg-do run }
+
+struct S { unsigned a; unsigned long long b; unsigned char c; } s = { 10,
53967718, 1 };
+auto [ a, b, c ] = s;
+volatile int v;
+
+int
+main ()
+{
+  v = 1;
+// { dg-final { gdb-test 11 "a" "10" } }
+// { dg-final { gdb-test 11 "b" "53967718" } }
+// { dg-final { gdb-test 11 "c" "1" } }
+}

This has still multiple problems.  Both are related to a/b/c not being in
varpool, only the underlying unnamed variable is.
For the default -feliminate-unused-debug-symbols, at namespace scope we simply
prune all DW_TAG_variable DIEs which aren't for vars in varpool (with some
special cases).
With -fno-eliminate-unused-debug-symbols and this patch, we get the
DW_TAG_variable DIEs for a/b/c, but not DW_AT_location for those, which is
because nothing calls dwarf2out_late_global_decl for those vars.  So for both
of these, I wonder if we shouldn't add some internal attribute (with space in
name) which would be attached to the underlying VAR_DECLs of structured
bindings at namespace scope if there are any VAR_DECLs with DECL_VALUE_EXPR
pointing into it, with the list of such VAR_DECLs and handle it in
premark_used_variables and dwarf2out_late_global_decl.

Reply via email to