public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/18861] 'reinterpret_cast' in gdb seems to be doing a 'static_cast'.
  2015-08-21 21:27 [Bug gdb/18861] New: 'reinterpret_cast' in gdb seems to be doing a 'static_cast' cs120hcc at yahoo dot com
@ 2015-08-21 21:27 ` cs120hcc at yahoo dot com
  2023-12-23 12:21 ` [Bug c++/18861] " ssbssa at sourceware dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: cs120hcc at yahoo dot com @ 2015-08-21 21:27 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=18861

cs120hcc at yahoo dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unknown                     |HEAD

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug gdb/18861] New: 'reinterpret_cast' in gdb seems to be doing a 'static_cast'.
@ 2015-08-21 21:27 cs120hcc at yahoo dot com
  2015-08-21 21:27 ` [Bug gdb/18861] " cs120hcc at yahoo dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: cs120hcc at yahoo dot com @ 2015-08-21 21:27 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=18861

            Bug ID: 18861
           Summary: 'reinterpret_cast' in gdb seems to be doing a
                    'static_cast'.
           Product: gdb
           Version: unknown
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: cs120hcc at yahoo dot com
  Target Milestone: ---

Created attachment 8544
  --> https://sourceware.org/bugzilla/attachment.cgi?id=8544&action=edit
Sample Code and Repro Transcript

Problem: 'reinterpret_cast' in gdb seems to be doing a 'static_cast'.

For example, assume we have two unrelated base classes, 'fred' and 'ginger',
and another class 'hillary' that first extends 'fred' then 'ginger'. 
Typically, a 'hillary' object would have the same address as the inherited
'fred' object.  The inherited 'ginger' object typically follows the 'fred'
data.  (It depends on the compiler implementation, but don't let that distract
you from the description of the gdb bug.)

'reinterpret_cast' typically does not change the value of a pointer that is
casts.  Specifically, given 'ginger*' pointer 'g',
'reinterpret_cast<hillary*>(g)' should have the same value as
'static_cast<hillary*>(static_cast<void*>(g))' per 5.2.10.7 of the 2011 and
2014 versions of the C++ standard (N3242 and N4296).  Notice that it does work
properly in code generated by g++.  However, in the various versions of gdb, it
does not.

The bug is reproduced is several GDB versions and distributions.
> GNU gdb (GDB) 7.4.1-debian          installed using apt-get
> GNU gdb (GDB) 7.9.1                 downloaded from gnu.org/software/gdb/download/
> GNU gdb (GDB) 7.10.50.20150818-cvs  downloaded from gnu.org/software/gdb/download/
> GNU gdb (Gentoo 7.5.1 p2) 7.5.1     installed using portage

Attached is sample code with several transcripts showing the problem.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/18861] 'reinterpret_cast' in gdb seems to be doing a 'static_cast'.
  2015-08-21 21:27 [Bug gdb/18861] New: 'reinterpret_cast' in gdb seems to be doing a 'static_cast' cs120hcc at yahoo dot com
  2015-08-21 21:27 ` [Bug gdb/18861] " cs120hcc at yahoo dot com
@ 2023-12-23 12:21 ` ssbssa at sourceware dot org
  2024-03-20 17:02 ` cvs-commit at gcc dot gnu.org
  2024-03-20 17:04 ` ssbssa at sourceware dot org
  3 siblings, 0 replies; 5+ messages in thread
From: ssbssa at sourceware dot org @ 2023-12-23 12:21 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=18861

Hannes Domani <ssbssa at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ssbssa at sourceware dot org

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/18861] 'reinterpret_cast' in gdb seems to be doing a 'static_cast'.
  2015-08-21 21:27 [Bug gdb/18861] New: 'reinterpret_cast' in gdb seems to be doing a 'static_cast' cs120hcc at yahoo dot com
  2015-08-21 21:27 ` [Bug gdb/18861] " cs120hcc at yahoo dot com
  2023-12-23 12:21 ` [Bug c++/18861] " ssbssa at sourceware dot org
@ 2024-03-20 17:02 ` cvs-commit at gcc dot gnu.org
  2024-03-20 17:04 ` ssbssa at sourceware dot org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-20 17:02 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=18861

--- Comment #1 from Sourceware Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Hannes Domani <ssbssa@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=23cdd9431ad424b092c65419d47ef4601168a1c9

commit 23cdd9431ad424b092c65419d47ef4601168a1c9
Author: Hannes Domani <ssbssa@yahoo.de>
Date:   Wed Mar 20 18:02:06 2024 +0100

    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>

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/18861] 'reinterpret_cast' in gdb seems to be doing a 'static_cast'.
  2015-08-21 21:27 [Bug gdb/18861] New: 'reinterpret_cast' in gdb seems to be doing a 'static_cast' cs120hcc at yahoo dot com
                   ` (2 preceding siblings ...)
  2024-03-20 17:02 ` cvs-commit at gcc dot gnu.org
@ 2024-03-20 17:04 ` ssbssa at sourceware dot org
  3 siblings, 0 replies; 5+ messages in thread
From: ssbssa at sourceware dot org @ 2024-03-20 17:04 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=18861

Hannes Domani <ssbssa at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |15.1

--- Comment #2 from Hannes Domani <ssbssa at sourceware dot org> ---
Fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-20 17:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-21 21:27 [Bug gdb/18861] New: 'reinterpret_cast' in gdb seems to be doing a 'static_cast' cs120hcc at yahoo dot com
2015-08-21 21:27 ` [Bug gdb/18861] " cs120hcc at yahoo dot com
2023-12-23 12:21 ` [Bug c++/18861] " ssbssa at sourceware dot org
2024-03-20 17:02 ` cvs-commit at gcc dot gnu.org
2024-03-20 17:04 ` ssbssa at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).