From: Hannes Domani <ssbssa@yahoo.de>
To: Tom Tromey <tom@tromey.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Fix casting in-memory values of primitive types to const reference
Date: Wed, 20 Mar 2024 17:25:57 +0000 (UTC) [thread overview]
Message-ID: <745860198.11199509.1710955557445@mail.yahoo.com> (raw)
In-Reply-To: <87msqsg7fa.fsf@tromey.com>
Am Mittwoch, 20. März 2024 um 18:05:48 MEZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:
> >>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
>
> Hannes> It's currently not possible to cast an in-memory value of a primitive
> Hannes> type to const reference:
>
> Thank you for the patch.
>
> I think it is ok. However I suspect there may be other bugs here.
>
> Approved-By: Tom Tromey <tom@tromey.com>
Pushed, thanks.
> Hannes> Fixed by ignoring const/volatile/restrict qualifications in
> Hannes> value_cast when comparing cast type to original type, so the new
> Hannes> value will point to the same location as the original value:
>
> Hannes> - if (types_deeply_equal (arg2->type (), type))
> Hannes> + if (types_deeply_equal (make_unqualified_type (arg2->type ()),
> Hannes> + make_unqualified_type (type)))
>
> This code seems slightly weird in that it isn't calling check_typedef.
> So, I wonder what happens if typedefs are involved, for example if you
> did:
>
> typedef const int ci;
>
> (gdb) print (ci&) Q.id
This happens:
(gdb) p (ci&) Q.id
$1 = (const int &) @0x3cfb8c: 42
Because check_typedef is called when the reference is removed:
```
/* Check if we are casting struct reference to struct reference. */
if (TYPE_IS_REFERENCE (check_typedef (type)))
{
/* We dereference type; then we recurse and finally
we generate value of the given reference. Nothing wrong with
that. */
struct type *t1 = check_typedef (type);
struct type *dereftype = check_typedef (t1->target_type ());
struct value *val = value_cast (dereftype, arg2);
return value_ref (val, t1->code ());
}
```
Hannes
next prev parent reply other threads:[~2024-03-20 17:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240320160844.106-1-ssbssa.ref@yahoo.de>
2024-03-20 16:08 ` Hannes Domani
2024-03-20 17:05 ` Tom Tromey
2024-03-20 17:25 ` Hannes Domani [this message]
2024-03-20 17:33 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=745860198.11199509.1710955557445@mail.yahoo.com \
--to=ssbssa@yahoo.de \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).