[03/11] gdb/testsuite: account for clang's recursive destructor calls on gdb.cp/mb-ctor.exp

Message ID 20221004170747.154307-4-blarsen@redhat.com
State Committed
Headers
Series Cleanup gdb.cp tests when running with clang |

Commit Message

Guinevere Larsen Oct. 4, 2022, 5:07 p.m. UTC
  When compiling virtual classes's destructors, two versions are compiled,
one with a single parameter (this) and the other with 2 parameters (this
and vtt).

GCC's compilation makes it so either the version with 1
parameter or the one with 2 parameters is called, depending on whether
the destructor is being called by the class itself or by an inherited
class. On the test gdb.cp/mb-ctor.exp, this means that the breakpoint
set at the destructor will be hit 4 times.

Clang, on the other hand, makes the single-parameter version call the 2
parameter version, probably in an attempt to reduce the size of the
resulting executable. This means that the gdb.cp/mb-ctor.exp will hit 6
breakpoints before finishing, and is the reason why this test was
failing. To make this test stop failing, a compiler check is added and
another "continue" instruction is issued to account for this difference.
---
 gdb/testsuite/gdb.cp/mb-ctor.exp | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
  

Comments

Andrew Burgess Oct. 26, 2022, 12:35 p.m. UTC | #1
Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org> writes:

> When compiling virtual classes's destructors, two versions are compiled,
> one with a single parameter (this) and the other with 2 parameters (this
> and vtt).
>
> GCC's compilation makes it so either the version with 1
> parameter or the one with 2 parameters is called, depending on whether
> the destructor is being called by the class itself or by an inherited
> class. On the test gdb.cp/mb-ctor.exp, this means that the breakpoint
> set at the destructor will be hit 4 times.
>
> Clang, on the other hand, makes the single-parameter version call the 2
> parameter version, probably in an attempt to reduce the size of the
> resulting executable. This means that the gdb.cp/mb-ctor.exp will hit 6
> breakpoints before finishing, and is the reason why this test was
> failing. To make this test stop failing, a compiler check is added and
> another "continue" instruction is issued to account for this difference.
> ---
>  gdb/testsuite/gdb.cp/mb-ctor.exp | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/gdb/testsuite/gdb.cp/mb-ctor.exp b/gdb/testsuite/gdb.cp/mb-ctor.exp
> index 5a3c0a4a90f..6aadecdd27d 100644
> --- a/gdb/testsuite/gdb.cp/mb-ctor.exp
> +++ b/gdb/testsuite/gdb.cp/mb-ctor.exp
> @@ -25,6 +25,12 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
>      return -1
>  }
>  
> +if {[test_compiler_info {clang-*-*}]} {

Include c++ language for test_compiler_info call (see previous patch for
details).

> +    set using_clang true
> +} else {
> +    set using_clang false
> +}
> +
>  if ![runto_main] then {
>      perror "couldn't run to breakpoint"
>      return
> @@ -71,6 +77,12 @@ gdb_continue_to_breakpoint "set breakpoint here, second dynamic time"\
>  
>  gdb_test "continue" ".*Breakpoint.*~Derived.*" "Run to dynamic destructor v1"
>  
> +# Clang makes Derived::~Derived(this) call Derived::~Derives(this, vtt)
> +# whereas gcc puts all the logic necessary on both functions.
> +if {$using_clang} {
> +    gdb_test "continue" ".*Breakpoint.*~Derived.*" "clang's recursive dynamic destructor call"

There lines are a little long, and should be wrapped.

Also, I'm not sure I agree with the use of 'recursive' here.  Maybe
'nested' would be better?  When I think recursive, I think of functions
that directly, or indirectly, call themselves.  Though the two
destructors do have the same name, I don't think they are the same
function.

> +}
> +
>  gdb_test "continue" ".*Breakpoint.*~Derived.*" "Run to dynamic destructor v2"
>  
>  gdb_test "continue" \
> @@ -81,6 +93,10 @@ gdb_test "continue" \
>      ".*Breakpoint.*~Derived.*" \
>      "run to breakpoint 3 v2"
>  
> +if {$using_clang} {
> +    gdb_test "continue" ".*Breakpoint.*~Derived.*" "clang's recursive destructor call"
> +}

Same again.

Thanks,
Andrew

> +
>  gdb_test "continue" \
>      ".*exited normally.*" \
>      "run to exit"
> -- 
> 2.37.3
  

Patch

diff --git a/gdb/testsuite/gdb.cp/mb-ctor.exp b/gdb/testsuite/gdb.cp/mb-ctor.exp
index 5a3c0a4a90f..6aadecdd27d 100644
--- a/gdb/testsuite/gdb.cp/mb-ctor.exp
+++ b/gdb/testsuite/gdb.cp/mb-ctor.exp
@@ -25,6 +25,12 @@  if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
     return -1
 }
 
+if {[test_compiler_info {clang-*-*}]} {
+    set using_clang true
+} else {
+    set using_clang false
+}
+
 if ![runto_main] then {
     perror "couldn't run to breakpoint"
     return
@@ -71,6 +77,12 @@  gdb_continue_to_breakpoint "set breakpoint here, second dynamic time"\
 
 gdb_test "continue" ".*Breakpoint.*~Derived.*" "Run to dynamic destructor v1"
 
+# Clang makes Derived::~Derived(this) call Derived::~Derives(this, vtt)
+# whereas gcc puts all the logic necessary on both functions.
+if {$using_clang} {
+    gdb_test "continue" ".*Breakpoint.*~Derived.*" "clang's recursive dynamic destructor call"
+}
+
 gdb_test "continue" ".*Breakpoint.*~Derived.*" "Run to dynamic destructor v2"
 
 gdb_test "continue" \
@@ -81,6 +93,10 @@  gdb_test "continue" \
     ".*Breakpoint.*~Derived.*" \
     "run to breakpoint 3 v2"
 
+if {$using_clang} {
+    gdb_test "continue" ".*Breakpoint.*~Derived.*" "clang's recursive destructor call"
+}
+
 gdb_test "continue" \
     ".*exited normally.*" \
     "run to exit"