public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/testsuite] Initialize anonymous union in gdb.cp/koenig.cc
@ 2021-10-26 11:39 Natarajan, Kavitha
  2021-10-26 20:39 ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Natarajan, Kavitha @ 2021-10-26 11:39 UTC (permalink / raw)
  To: Natarajan, Kavitha via Gdb-patches, Tom Tromey; +Cc: George, Jini Susan

[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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [gdb/testsuite] Initialize anonymous union in gdb.cp/koenig.cc
  2021-10-26 11:39 [PATCH] [gdb/testsuite] Initialize anonymous union in gdb.cp/koenig.cc Natarajan, Kavitha
@ 2021-10-26 20:39 ` Tom Tromey
  2021-10-27  5:05   ` Natarajan, Kavitha
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2021-10-26 20:39 UTC (permalink / raw)
  To: Natarajan, Kavitha via Gdb-patches
  Cc: Tom Tromey, Natarajan, Kavitha, George, Jini Susan

>> 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".

Hi.  Thanks for updating the patch.

>> +#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

If this is all it takes, it seems like this could be done
unconditionally; that is without checking __clang__.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] [gdb/testsuite] Initialize anonymous union in gdb.cp/koenig.cc
  2021-10-26 20:39 ` Tom Tromey
@ 2021-10-27  5:05   ` Natarajan, Kavitha
  2021-10-27 15:03     ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Natarajan, Kavitha @ 2021-10-27  5:05 UTC (permalink / raw)
  To: Tom Tromey, Natarajan, Kavitha via Gdb-patches; +Cc: George, Jini Susan

[AMD Official Use Only]

Hi Tom,

Please find the updated patch:

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

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

+  p_union = {0};
+
   P::Q q;
   q == 5;
   q == 5.0f;
--

Regards,
Kavitha

-----Original Message-----
From: Tom Tromey <tom@tromey.com> 
Sent: Wednesday, October 27, 2021 2:09 AM
To: Natarajan, Kavitha via Gdb-patches <gdb-patches@sourceware.org>
Cc: Tom Tromey <tom@tromey.com>; Natarajan, Kavitha <Kavitha.Natarajan@amd.com>; George, Jini Susan <JiniSusan.George@amd.com>
Subject: Re: [PATCH] [gdb/testsuite] Initialize anonymous union in gdb.cp/koenig.cc

[CAUTION: External Email]

>> 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".

Hi.  Thanks for updating the patch.

>> +#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

If this is all it takes, it seems like this could be done unconditionally; that is without checking __clang__.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [gdb/testsuite] Initialize anonymous union in gdb.cp/koenig.cc
  2021-10-27  5:05   ` Natarajan, Kavitha
@ 2021-10-27 15:03     ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2021-10-27 15:03 UTC (permalink / raw)
  To: Natarajan, Kavitha
  Cc: Tom Tromey, Natarajan, Kavitha via Gdb-patches, George, Jini Susan

>> Please find the updated patch:

Looks good.  Thank you.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-27 15:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-26 11:39 [PATCH] [gdb/testsuite] Initialize anonymous union in gdb.cp/koenig.cc Natarajan, Kavitha
2021-10-26 20:39 ` Tom Tromey
2021-10-27  5:05   ` Natarajan, Kavitha
2021-10-27 15:03     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).