public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Basic frontend question about layout
@ 2009-06-24  3:52 Jerry Quinn
  2009-06-24  4:18 ` Andrew Pinski
  0 siblings, 1 reply; 4+ messages in thread
From: Jerry Quinn @ 2009-06-24  3:52 UTC (permalink / raw)
  To: gcc

Hi, folks,

I'm having trouble seeing how layout is specified at the GENERIC level
for RECORD_TYPEs.  The docs and comments in tree.def say that you cannot
rely on the order of fields of the type.  In stor-layout.c,
layout_types() seems to do the obvious thing, taking the fields in
order, but the docs make it sound like there is no way to be sure what
you'll get.

Theoretically this would mean that you couldn't even reliably link a
structure in two separate compilation units, which is bogus.

Could someone please clear up my confusion?

Thanks,
Jerry Quinn


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

* Re: Basic frontend question about layout
  2009-06-24  3:52 Basic frontend question about layout Jerry Quinn
@ 2009-06-24  4:18 ` Andrew Pinski
  2009-06-24  5:41   ` Jerry Quinn
  2009-06-24  8:56   ` Eric Botcazou
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Pinski @ 2009-06-24  4:18 UTC (permalink / raw)
  To: Jerry Quinn; +Cc: gcc

On Tue, Jun 23, 2009 at 8:48 PM, Jerry Quinn<jlquinn@optonline.net> wrote:
> Hi, folks,
>
> I'm having trouble seeing how layout is specified at the GENERIC level
> for RECORD_TYPEs.  The docs and comments in tree.def say that you cannot
> rely on the order of fields of the type.  In stor-layout.c,
> layout_types() seems to do the obvious thing, taking the fields in
> order, but the docs make it sound like there is no way to be sure what
> you'll get.
> Could someone please clear up my confusion?

The confusion here is that layout_types is separate from the rest of
the middle-end and the front-end could do the layout themselves and
the front-end calls layout_type if it does not do the layout itself.

So for an example, Ada layouts the records themselves and some times
has a different order of the fields than the layouted offsets.

Thanks,
Andrew Pinski

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

* Re: Basic frontend question about layout
  2009-06-24  4:18 ` Andrew Pinski
@ 2009-06-24  5:41   ` Jerry Quinn
  2009-06-24  8:56   ` Eric Botcazou
  1 sibling, 0 replies; 4+ messages in thread
From: Jerry Quinn @ 2009-06-24  5:41 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc

On Tue, 2009-06-23 at 20:52 -0700, Andrew Pinski wrote:
> On Tue, Jun 23, 2009 at 8:48 PM, Jerry Quinn<jlquinn@optonline.net> wrote:
> > Hi, folks,
> >
> > I'm having trouble seeing how layout is specified at the GENERIC level
> > for RECORD_TYPEs.  The docs and comments in tree.def say that you cannot
> > rely on the order of fields of the type.  In stor-layout.c,
> > layout_types() seems to do the obvious thing, taking the fields in
> > order, but the docs make it sound like there is no way to be sure what
> > you'll get.
> > Could someone please clear up my confusion?
> 
> The confusion here is that layout_types is separate from the rest of
> the middle-end and the front-end could do the layout themselves and
> the front-end calls layout_type if it does not do the layout itself.

As I look at the code, it seems like a front end doesn't actually need
to call layout_type at all.  Is that correct?  If so, is the layout
C-compatible, assuming the field types being used are individually
compatible?

I'm gleaning this from a mix of code, comments, and gccint texinfo docs.
Would it make sense to update them to indicate that layout is in order
as long as the rest of the language-specific front end doesn't choose to
lay things out differently?

Thanks,
Jerry


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

* Re: Basic frontend question about layout
  2009-06-24  4:18 ` Andrew Pinski
  2009-06-24  5:41   ` Jerry Quinn
@ 2009-06-24  8:56   ` Eric Botcazou
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Botcazou @ 2009-06-24  8:56 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc, Jerry Quinn

> So for an example, Ada layouts the records themselves and some times
> has a different order of the fields than the layouted offsets.

The Ada compiler uses stor-layout.c by default, like all the other compilers.
It does its own layout only when it has nothing to do, i.e. when the user has 
specified the layout with a representation clause; and, in this case, it does 
sort the fields by increasing offsets (see components_to_record) because the 
middle-end expects the canonical order in various circumstances.

-- 
Eric Botcazou

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

end of thread, other threads:[~2009-06-24  7:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-24  3:52 Basic frontend question about layout Jerry Quinn
2009-06-24  4:18 ` Andrew Pinski
2009-06-24  5:41   ` Jerry Quinn
2009-06-24  8:56   ` Eric Botcazou

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