From: Richard Biener <richard.guenther@gmail.com>
To: Martin Sebor <msebor@gmail.com>
Cc: GCC Mailing List <gcc@gcc.gnu.org>
Subject: Re: determining aggregate member from MEM_REF
Date: Fri, 16 Feb 2018 11:22:00 -0000 [thread overview]
Message-ID: <CAFiYyc02CumJYaSG5x7QvSzN+0wyVKXGY=uvyHB+76Z5QxwNCQ@mail.gmail.com> (raw)
In-Reply-To: <108da35d-4146-2b3a-a667-692d41bcf8f6@gmail.com>
On Thu, Feb 15, 2018 at 6:28 PM, Martin Sebor <msebor@gmail.com> wrote:
> There are APIs to determine the base object and an offset
> into it from all sorts of expressions, including ARRAY_REF,
> COMPONENT_REF, and MEM_REF, but none of those I know about
> makes it also possible to discover the member being referred
> to.
>
> Is there an API that I'm missing or a combination of calls
> to some that would let me determine the (approximate) member
> and/or element of an aggregate from a MEM_REF expression,
> plus the offset from its beginning?
>
> Say, given
>
> struct A
> {
> void *p;
> char b[3][9];
> } a[2];
>
> and an expression like
>
> a[1].b[2] + 3
>
> represented as the expr
>
> MEM_REF (char[9], a, 69)
&MEM_REF (&a, 69)
you probably mean.
> where offsetof (struct A, a[1].b[2]) == 66
>
> I'd like to be able to determine that expr refers to the field
> b of struct A, and more specifically, b[2], plus 3. It's not
> important what the index into the array a is, or any other
> arrays on the way to b.
There is code in initializer folding that searches for a field in
a CONSTRUCTOR by base and offset. There's no existing
helper that gives you exactly what you want -- I guess you'd
ideally want to have a path to the refered object. But it may
be possible to follow what fold_ctor_reference does and build
such a helper.
> I realize the reference can be ambiguous in some cases (arrays
> of structs with multiple array members) and so the result wouldn't
> be guaranteed to be 100% reliable. It would only be used in
> diagnostics. (I think with some effort the type of the MEM_REF
> could be used to disambiguate the majority (though not all) of
> these references in practice.)
Given you have the address of the MEM_REF in your example above
the type of the MEM_REF doesn't mean anything.
I think ambiguity only happens with unions given MEM_REF offsets
are constant.
Note that even the type of 'a' might not be correct as it may have had
a different dynamic type.
So not sure what context you are trying to use this in diagnostics.
Richard.
>
> Thanks
> Martin
next prev parent reply other threads:[~2018-02-16 11:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-15 17:28 Martin Sebor
2018-02-16 11:22 ` Richard Biener [this message]
2018-02-16 19:07 ` Martin Sebor
2018-02-26 12:08 ` Richard Biener
2018-02-26 15:44 ` Martin Sebor
2018-02-26 20:05 ` Jeff Law
2018-02-27 13:27 ` Richard Biener
2018-02-26 19:57 ` Jeff Law
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='CAFiYyc02CumJYaSG5x7QvSzN+0wyVKXGY=uvyHB+76Z5QxwNCQ@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=gcc@gcc.gnu.org \
--cc=msebor@gmail.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).