public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* determining aggregate member from MEM_REF
@ 2018-02-15 17:28 Martin Sebor
  2018-02-16 11:22 ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Sebor @ 2018-02-15 17:28 UTC (permalink / raw)
  To: GCC Mailing List

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)

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.

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.)

Thanks
Martin

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

end of thread, other threads:[~2018-02-27 13:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-15 17:28 determining aggregate member from MEM_REF Martin Sebor
2018-02-16 11:22 ` Richard Biener
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

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).