aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorHannes Domani <ssbssa@yahoo.de>2024-03-20 18:02:06 +0100
committerHannes Domani <ssbssa@yahoo.de>2024-03-20 18:02:06 +0100
commit23cdd9431ad424b092c65419d47ef4601168a1c9 (patch)
treeafb675baa8627d111c515e4b733f4f915fd7d7f0 /gdb/testsuite
parente8f6050cfb990452fcfc685bc9ccbae79113fa36 (diff)
downloadbinutils-23cdd9431ad424b092c65419d47ef4601168a1c9.zip
binutils-23cdd9431ad424b092c65419d47ef4601168a1c9.tar.gz
binutils-23cdd9431ad424b092c65419d47ef4601168a1c9.tar.bz2
Fix reinterpret_cast for classes with multiple inheritance
Currently a reinterpret_cast may change the pointer value if multiple inheritance is involved: ``` (gdb) p r $1 = (Right *) 0x22f75c (gdb) p reinterpret_cast<LeftRight*>(r) $2 = (LeftRight *) 0x22f758 ``` It's because value_cast is called in this case, which automatically does up- and downcasting. Fixed by simply using the target pointer type in a copy of the original value: ``` (gdb) p r $1 = (Right *) 0x3bf87c (gdb) p reinterpret_cast<LeftRight*>(r) $2 = (LeftRight *) 0x3bf87c ``` Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18861 Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.cp/casts.cc8
-rw-r--r--gdb/testsuite/gdb.cp/casts.exp10
2 files changed, 18 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.cp/casts.cc b/gdb/testsuite/gdb.cp/casts.cc
index 5c7f9dc..eacd8bc 100644
--- a/gdb/testsuite/gdb.cp/casts.cc
+++ b/gdb/testsuite/gdb.cp/casts.cc
@@ -88,6 +88,14 @@ main (int argc, char **argv)
unsigned long long gd_value = (unsigned long long) (std::uintptr_t)&gd;
unsigned long long r_value = (unsigned long long) (Right *) &gd;
+ LeftRight *lr = &gd;
+ Left *l = lr;
+ Right *r = lr;
+ LeftRight *lr_l = reinterpret_cast<LeftRight *>(l);
+ LeftRight *lr_r = reinterpret_cast<LeftRight *>(r);
+ Left *l_lr = reinterpret_cast<Left *>(lr);
+ Right *r_lr = reinterpret_cast<Right *>(lr);
+
VirtualLeftRight *vlr = new VirtualLeftRight ();
VirtualLeft *vl = vlr;
VirtualRight *vr = vlr;
diff --git a/gdb/testsuite/gdb.cp/casts.exp b/gdb/testsuite/gdb.cp/casts.exp
index 7bfc93b..ca82ab0 100644
--- a/gdb/testsuite/gdb.cp/casts.exp
+++ b/gdb/testsuite/gdb.cp/casts.exp
@@ -180,6 +180,16 @@ gdb_test "print (unsigned long long) (LeftRight *) (Right *) &gd == gd_value" \
gdb_test "print (unsigned long long) (LeftRight *) (Right *) r_value == gd_value" \
" = true"
+gdb_test "print reinterpret_cast<LeftRight *>(l) == lr_l" " = true"
+gdb_test "print reinterpret_cast<LeftRight *>(r) == lr_r" " = true"
+gdb_test "print reinterpret_cast<Left *>(lr) == l_lr" " = true"
+gdb_test "print reinterpret_cast<Right *>(lr) == r_lr" " = true"
+
+gdb_test "print &reinterpret_cast<LeftRight &>(*l) == lr_l" " = true"
+gdb_test "print &reinterpret_cast<LeftRight &>(*r) == lr_r" " = true"
+gdb_test "print &reinterpret_cast<Left &>(*lr) == l_lr" " = true"
+gdb_test "print &reinterpret_cast<Right &>(*lr) == r_lr" " = true"
+
gdb_test "print dynamic_cast<VirtualLeftRight *> (vlr) == vlr" " = true"
gdb_test "print dynamic_cast<VirtualLeftRight *> (vl) == vlr" " = true"
gdb_test "print dynamic_cast<VirtualLeftRight *> (vr) == vlr" " = true"