[PATCH] [gdb/testsuite] Initialize anonymous union in gdb.cp/koenig.cc

Natarajan, Kavitha Kavitha.Natarajan@amd.com
Tue Oct 26 11:39:43 GMT 2021


[AMD Official Use Only]

Hi Tom and all,

Please review the gdb test case change for clang to emit the debug info for unused anonymous union variable. This change is to accommodate Tom's review comment for the patch "[PATCH] [gdb/testsuite] Add a clang option to gdb.cp/koenig.exp".

---
GDB test fails while running the test case gdb.cp/koenig.exp using
clang compiler:
[...]
p foo (p_union)
No symbol "p_union" in current context.
(gdb) FAIL: gdb.cp/koenig.exp: p foo (p_union)
[...]

In the testcase, "p_union" is an unused/uninitialized variable of
anonymous union type. Clang does not emit symbol for unused anonymous
union/struct variables at any optimization level. Since the compiler
itself is not emitting the symbol for "p_union", debug info is also
not emitted when built with debug option. If the anonymous union is
initialized (or used), then clang emits the symbol "p_union" which
enables emitting debug info for "p_union".
[...]
p foo (p_union)
Cannot resolve function foo to any overloaded instance
(gdb) PASS: gdb.cp/koenig.exp: p foo (p_union)
[...]

---
gdb/testsuite/gdb.cp/koenig.cc | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/gdb/testsuite/gdb.cp/koenig.cc b/gdb/testsuite/gdb.cp/koenig.cc
index 01e2637cfbd..f2047b5176c 100644
--- a/gdb/testsuite/gdb.cp/koenig.cc
+++ b/gdb/testsuite/gdb.cp/koenig.cc
@@ -305,6 +305,12 @@ main ()
   TTOA ttoa;
   foo (ttoa, 'a');

+#if defined (__clang__)
+  // Initialize anonymous union for clang to emit the symbol
+  // Dwarf info is emitted only if the symbol is emitted.
+  p_union = {0};
+#endif
+
   P::Q q;
   q == 5;
   q == 5.0f;
--

Regards,
Kavitha


More information about the Gdb-patches mailing list