aboutsummaryrefslogtreecommitdiff
path: root/gdb/valops.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-04-02 09:54:40 -0600
committerTom Tromey <tom@tromey.com>2022-04-18 09:34:55 -0600
commit2390419d1cb72882110538e01e5586372df19657 (patch)
tree184695bb4127c296ef8c1305e48fca1c0e27fdfb /gdb/valops.c
parentc67f4e53895da91ce7f2eff3544e9de02280f740 (diff)
downloadbinutils-2390419d1cb72882110538e01e5586372df19657.zip
binutils-2390419d1cb72882110538e01e5586372df19657.tar.gz
binutils-2390419d1cb72882110538e01e5586372df19657.tar.bz2
Fix C++ cast of derived class to base class
PR c++/28907 points out that casting from a derived class to a base class fails in some situations. The problem turned out to be a missing use of value_embedded_offset. One peculiarity here is that, if you managed to construct a pointer-to-derived with an embedded offset of 0, the cast would work -- for example, one of the two new tests here passes without the patch. This embedded offset stuff is an endless source of bugs. I wonder if it's possible to get rid of it somehow. Regression tested on x86-64 Fedora 34. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28907
Diffstat (limited to 'gdb/valops.c')
-rw-r--r--gdb/valops.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/gdb/valops.c b/gdb/valops.c
index 42a1213..e84cabf 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -274,7 +274,7 @@ value_cast_structs (struct type *type, struct value *v2)
if (v)
{
/* Downcasting is possible (t1 is superclass of v2). */
- CORE_ADDR addr2 = value_address (v2);
+ CORE_ADDR addr2 = value_address (v2) + value_embedded_offset (v2);
addr2 -= value_address (v) + value_embedded_offset (v);
return value_at (type, addr2);