CodeView local symbol records require a name, but artificial local
variables can have no DW_AT_name. Attempting to emit such variables
dereferences a null pointer. Skip unnamed locals in each local symbol
writer.
gcc/ChangeLog:
PR debug/124432
* dwarf2codeview.cc (write_s_local): Skip unnamed variables.
(write_local_s_ldata32): Likewise.
(write_s_register): Likewise.
(write_fbreg_variable): Likewise.
gcc/testsuite/ChangeLog:
PR debug/124432
* g++.dg/debug/codeview/codeview.exp: New test driver.
* g++.dg/debug/codeview/pr124432.C: New test.
---
gcc/dwarf2codeview.cc | 12 +++++
.../g++.dg/debug/codeview/codeview.exp | 48 +++++++++++++++++++
.../g++.dg/debug/codeview/pr124432.C | 17 +++++++
3 files changed, 77 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/debug/codeview/codeview.exp
create mode 100644 gcc/testsuite/g++.dg/debug/codeview/pr124432.C
diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index 252059d301..8786887bdf 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -2281,6 +2281,9 @@ write_s_local (dw_die_ref die)
const char *name = get_AT_string (die, DW_AT_name);
uint32_t type;
+ if (!name)
+ return;
+
/* This is struct LOCALSYM in Microsoft's cvinfo.h:
struct LOCALSYM {
@@ -2331,6 +2334,9 @@ write_local_s_ldata32 (dw_die_ref die, dw_loc_descr_ref
loc_ref)
const char *name = get_AT_string (die, DW_AT_name);
uint32_t type;
+ if (!name)
+ return;
+
/* This is struct datasym in binutils:
struct datasym
@@ -2522,6 +2528,9 @@ write_s_register (dw_die_ref die, dw_loc_descr_ref
loc_ref)
uint16_t regno;
uint32_t type;
+ if (!name)
+ return;
+
/* This is struct regsym in binutils and REGSYM in Microsoft's cvinfo.h:
struct regsym
@@ -2584,6 +2593,9 @@ write_fbreg_variable (dw_die_ref die, dw_loc_descr_ref
loc_ref,
uint16_t regno;
int offset;
+ if (!name)
+ return;
+
/* This is struct regrel in binutils and REGREL32 in Microsoft's cvinfo.h:
struct regrel
diff --git a/gcc/testsuite/g++.dg/debug/codeview/codeview.exp
b/gcc/testsuite/g++.dg/debug/codeview/codeview.exp
new file mode 100644
index 0000000000..044f91f4eb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/codeview/codeview.exp
@@ -0,0 +1,48 @@
+# Copyright (C) 2026 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# G++ testsuite that uses the `dg.exp' driver.
+
+# Load support procs.
+load_lib g++-dg.exp
+
+if {![istarget i*86-*-mingw*]
+ && ![istarget x86_64-*-mingw*]} {
+ return 0
+}
+
+# If a testcase doesn't have special options, use these.
+global DEFAULT_CXXFLAGS
+if ![info exists DEFAULT_CXXFLAGS] then {
+ set DEFAULT_CXXFLAGS " -pedantic-errors -Wno-long-long"
+}
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+set comp_output [g++_target_compile \
+ "$srcdir/$subdir/../trivial.C" "trivial.S" assembly \
+ "additional_flags=-gcodeview"]
+if { ! [string match "*: target system does not support the * debug format*" \
+ $comp_output] } {
+ remove-build-file "trivial.S"
+ g++-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C]] \
+ "" $DEFAULT_CXXFLAGS
+}
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/g++.dg/debug/codeview/pr124432.C
b/gcc/testsuite/g++.dg/debug/codeview/pr124432.C
new file mode 100644
index 0000000000..847d11ee39
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/codeview/pr124432.C
@@ -0,0 +1,17 @@
+// PR debug/124432
+// { dg-do compile }
+// { dg-options "-std=c++17 -O0 -gcodeview" }
+
+// write_fbreg_variable must not dereference a missing DW_AT_name for the
+// artificial structured-binding variable.
+
+struct S
+{
+ int a, b;
+};
+
+void
+f ()
+{
+ auto [a, b] = S {};
+}
--
2.55.0.windows.5