aboutsummaryrefslogtreecommitdiff
path: root/gdb/valops.c
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/valops.c
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/valops.c')
-rw-r--r--gdb/valops.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/gdb/valops.c b/gdb/valops.c
index be90744..1a943f0 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -694,10 +694,17 @@ value_reinterpret_cast (struct type *type, struct value *arg)
|| (dest_code == TYPE_CODE_MEMBERPTR && arg_code == TYPE_CODE_INT)
|| (dest_code == TYPE_CODE_INT && arg_code == TYPE_CODE_MEMBERPTR)
|| (dest_code == arg_code
- && (dest_code == TYPE_CODE_PTR
- || dest_code == TYPE_CODE_METHODPTR
+ && (dest_code == TYPE_CODE_METHODPTR
|| dest_code == TYPE_CODE_MEMBERPTR)))
result = value_cast (dest_type, arg);
+ else if (dest_code == TYPE_CODE_PTR && arg_code == TYPE_CODE_PTR)
+ {
+ /* Don't do any up- or downcasting. */
+ result = arg->copy ();
+ result->deprecated_set_type (dest_type);
+ result->set_enclosing_type (dest_type);
+ result->set_pointed_to_offset (0);
+ }
else
error (_("Invalid reinterpret_cast"));