[gdb/testsuite] Add a clang option to gdb.cp/koenig.exp

Message ID CY4PR12MB1237D0A593F4569F1AD4F626F7B69@CY4PR12MB1237.namprd12.prod.outlook.com
State New
Headers show
Series
  • [gdb/testsuite] Add a clang option to gdb.cp/koenig.exp
Related show

Commit Message

Andrew Burgess via Gdb-patches Oct. 12, 2021, 8:19 a.m.
[AMD Official Use Only]

Hi all,

I request you to please review the patch to fix the gdb.cp/Koenig.exp test failure with clang.

--

While running the test case gdb.cp/koenig.exp, there is an
unexpected failure:
[...]
p foo (p_union)
No symbol "p_union" in current context.
(gdb) FAIL: gdb.cp/koenig.exp: p foo (p_union)
[...]

In the testcase, "foo" is an unused variable of unnamed union type.
Clang does not emit symbol for unused unnamed union/struct variables
at any optimization level. Since the compiler itself is not emitting
the symbol for "foo", debug info is also not emitted when built with
debug option. Hence the failure. If clang option -femit-all-decls is
added to the compile line, the compiler would emit symbol for unused
unnamed union/struct variables (-g & -O0, optimized out at higher opt
levels) and thus the debug info. To fix the test failure,
-femit-all-decls is added.
[...]
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.exp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

--

Regards,
Kavitha

Comments

Andrew Burgess via Gdb-patches Oct. 25, 2021, 5:01 a.m. | #1
[AMD Official Use Only]

Hi all,

A gentle reminder. Please review the simple fix in gdb test provided in the below patch.

Regards,
Kavitha

From: Natarajan, Kavitha

Sent: Tuesday, October 12, 2021 1:50 PM
To: gdb-patches@sourceware.org
Cc: George, Jini Susan <JiniSusan.George@amd.com>; Parasuraman, Hariharan <Hariharan.Parasuraman@amd.com>
Subject: [PATCH] [gdb/testsuite] Add a clang option to gdb.cp/koenig.exp


[AMD Official Use Only]

Hi all,

I request you to please review the patch to fix the gdb.cp/Koenig.exp test failure with clang.

--

While running the test case gdb.cp/koenig.exp, there is an
unexpected failure:
[...]
p foo (p_union)
No symbol "p_union" in current context.
(gdb) FAIL: gdb.cp/koenig.exp: p foo (p_union)
[...]

In the testcase, "foo" is an unused variable of unnamed union type.
Clang does not emit symbol for unused unnamed union/struct variables
at any optimization level. Since the compiler itself is not emitting
the symbol for "foo", debug info is also not emitted when built with
debug option. Hence the failure. If clang option -femit-all-decls is
added to the compile line, the compiler would emit symbol for unused
unnamed union/struct variables (-g & -O0, optimized out at higher opt
levels) and thus the debug info. To fix the test failure,
-femit-all-decls is added.
[...]
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.exp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.cp/koenig.exp b/gdb/testsuite/gdb.cp/koenig.exp
index 86350fa5ad4..35e67e826d2 100644
--- a/gdb/testsuite/gdb.cp/koenig.exp
+++ b/gdb/testsuite/gdb.cp/koenig.exp
@@ -15,8 +15,13 @@

standard_testfile .cc

+set additional_flags ""
+if {[test_compiler_info "clang*"]} {
+    set additional_flags "additional_flags=-femit-all-decls"
+}
+
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
-      {debug c++ additional_flags=-Wno-unused-comparison}] } {
+      [list debug c++ additional_flags=-Wno-unused-comparison ${additional_flags}]] } {
      return -1
}

--

Regards,
Kavitha
Tom Tromey Oct. 25, 2021, 6:23 p.m. | #2
>>>>> ">" == Natarajan, Kavitha via Gdb-patches <gdb-patches@sourceware.org> writes:


>> In the testcase, "foo" is an unused variable of unnamed union type.

>> Clang does not emit symbol for unused unnamed union/struct variables

>> at any optimization level.


Is it possible to change the test so that the variable is used?
I think that would be preferable, if it is possible.

thanks,
Tom
Andrew Burgess via Gdb-patches Oct. 26, 2021, 11:25 a.m. | #3
[AMD Official Use Only]

Hi Tom,

Thanks for the review. It is possible to initialize the variable and generate the debug info for the unnamed/anonymous union variable. I will create the new patch and send it for review.

Regards,
Kavitha

-----Original Message-----
From: Tom Tromey <tom@tromey.com> 

Sent: Monday, October 25, 2021 11:54 PM
To: Natarajan, Kavitha via Gdb-patches <gdb-patches@sourceware.org>
Cc: Natarajan, Kavitha <Kavitha.Natarajan@amd.com>; George, Jini Susan <JiniSusan.George@amd.com>; Parasuraman, Hariharan <Hariharan.Parasuraman@amd.com>
Subject: Re: [PATCH] [gdb/testsuite] Add a clang option to gdb.cp/koenig.exp

[CAUTION: External Email]

>>>>> ">" == Natarajan, Kavitha via Gdb-patches <gdb-patches@sourceware.org> writes:


>> In the testcase, "foo" is an unused variable of unnamed union type.

>> Clang does not emit symbol for unused unnamed union/struct variables 

>> at any optimization level.


Is it possible to change the test so that the variable is used?
I think that would be preferable, if it is possible.

thanks,
Tom

Patch

diff --git a/gdb/testsuite/gdb.cp/koenig.exp b/gdb/testsuite/gdb.cp/koenig.exp
index 86350fa5ad4..35e67e826d2 100644
--- a/gdb/testsuite/gdb.cp/koenig.exp
+++ b/gdb/testsuite/gdb.cp/koenig.exp
@@ -15,8 +15,13 @@ 

standard_testfile .cc

+set additional_flags ""
+if {[test_compiler_info "clang*"]} {
+    set additional_flags "additional_flags=-femit-all-decls"
+}
+
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
-      {debug c++ additional_flags=-Wno-unused-comparison}] } {
+      [list debug c++ additional_flags=-Wno-unused-comparison ${additional_flags}]] } {
      return -1
}