public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits
@ 2005-06-29 22:57 Daniel Berlin
  2005-06-29 23:55 ` Richard Henderson
  2005-06-30 18:48 ` Giovanni Bajo
  0 siblings, 2 replies; 11+ messages in thread
From: Daniel Berlin @ 2005-06-29 22:57 UTC (permalink / raw)
  To: Gcc Mailing List

Why is that C++ can't create normal DECL's like everyone else?

Case in point:

(gdb)
 <parm_decl 0x40125000 it
    type <record_type 0x4010b2f4 node_iterator needs-constructing type_1
type_5 type_6 BLK
        size <integer_cst 0x4002aa80 constant invariant 96>
        unit size <integer_cst 0x4002aa98 constant invariant 12>
...

    addressable used BLK file minimal.c line 194 size <integer_cst
0x4002a960 0> unit size <integer_cst 0x4002a198 0>
$11 = void
(gdb) y



So we've got a parm decl that if you ask it for the DECL_SIZE, says 0,
but has a TYPE_SIZE of 12 bytes, and we access fields in it, etc.


This is causing a bug in detecting what portions of structures are used
in tree-ssa-alias, because we use DECL_SIZE, and this causes us to think
we use no part of the structure, since it gets min/max of 0!


I'm going to work around this by using TYPE_SIZE, but it would be nice
if somebody could explain the purpose for this behavior (if it's a bug,
i'll file a bug report). I would imagine we don't have truly empty
things in C++, so you could simply assert that TREE_INT_CST_LOW of
whatever you are setting DECL_SIZE to is not 0 and find these that way.


--Dan



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

* Re: PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits
  2005-06-29 22:57 PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits Daniel Berlin
@ 2005-06-29 23:55 ` Richard Henderson
  2005-06-30  1:17   ` Daniel Berlin
  2005-06-30 18:48 ` Giovanni Bajo
  1 sibling, 1 reply; 11+ messages in thread
From: Richard Henderson @ 2005-06-29 23:55 UTC (permalink / raw)
  To: Daniel Berlin; +Cc: Gcc Mailing List

On Wed, Jun 29, 2005 at 06:57:12PM -0400, Daniel Berlin wrote:
> I'm going to work around this by using TYPE_SIZE, but it would be nice
> if somebody could explain the purpose for this behavior (if it's a bug,
> i'll file a bug report). I would imagine we don't have truly empty
> things in C++, so you could simply assert that TREE_INT_CST_LOW of
> whatever you are setting DECL_SIZE to is not 0 and find these that way.

It is most definitely a bug.  I'm surprised about the 0 instead
of a NULL there.  The later would easily be explicable by 
forgetting to call layout_decl.

My only guess is that this decl had an incomplete type at some
point.  Is the function in question a template?  I could see as
how maybe we need to call relayout_decl after instantiation, or
simply re-order how the parm_decls are created.


r~

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

* Re: PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits
  2005-06-29 23:55 ` Richard Henderson
@ 2005-06-30  1:17   ` Daniel Berlin
  2005-06-30  4:35     ` [C++] " Richard Henderson
  2005-07-05 15:35     ` Mark Mitchell
  0 siblings, 2 replies; 11+ messages in thread
From: Daniel Berlin @ 2005-06-30  1:17 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Gcc Mailing List

On Wed, 2005-06-29 at 16:55 -0700, Richard Henderson wrote:
> On Wed, Jun 29, 2005 at 06:57:12PM -0400, Daniel Berlin wrote:
> > I'm going to work around this by using TYPE_SIZE, but it would be nice
> > if somebody could explain the purpose for this behavior (if it's a bug,
> > i'll file a bug report). I would imagine we don't have truly empty
> > things in C++, so you could simply assert that TREE_INT_CST_LOW of
> > whatever you are setting DECL_SIZE to is not 0 and find these that way.
> 
> It is most definitely a bug.  I'm surprised about the 0 instead
> of a NULL there.  The later would easily be explicable by 
> forgetting to call layout_decl.


Okay, well, here's what happens:

1. layout_decl gets called on the original PARM_DECL, when it's still a
template parameter, which sets the size to type_size, which is still 0
at that point, so we get DECL_SIZE of INTEGER_CST (0).

2. We copy the parm_decl when instantiating the template.

3. layout_decl gets called later on the copy of the PARM_DECL in the
instantiated function, which has a DECL_SIZE of INTEGER_CST (0) still.

layout_decl does nothing to DECL_SIZE and DECL_SIZE_UNIT of this
PARM_DECL in this case, even though TYPE_SIZE has changed from 0 to 96
bits.


I imagine the correct thing to do here is to 
1. In require_complete_types_for_parms, in the C++ FE, reset DECL_SIZE
to NULL before we call layout_decl on the parm and let layout_decl
figure out what to do.

or

2. Add code in layout_decl to copy TYPE_SIZE/TYPE_SIZE_UNIT if the
DECL_SIZE is integer_cst (0)
or

3. Not call layout_decl on the template types until they are completed.


Doing 1 fixes the bug I'm seeing and seems to do the correct thing, but
I'm not a C++ person, so there may be dragons this way.

--Dan




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

* [C++] Re: PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits
  2005-06-30  1:17   ` Daniel Berlin
@ 2005-06-30  4:35     ` Richard Henderson
  2005-06-30 21:12       ` Geoffrey Keating
  2005-07-05 15:35     ` Mark Mitchell
  1 sibling, 1 reply; 11+ messages in thread
From: Richard Henderson @ 2005-06-30  4:35 UTC (permalink / raw)
  To: Daniel Berlin; +Cc: Gcc Mailing List

On Wed, Jun 29, 2005 at 09:17:07PM -0400, Daniel Berlin wrote:
> 1. In require_complete_types_for_parms, in the C++ FE, reset DECL_SIZE
> to NULL before we call layout_decl on the parm and let layout_decl
> figure out what to do.

This is what relayout_decl does.

> 2. Add code in layout_decl to copy TYPE_SIZE/TYPE_SIZE_UNIT if the
> DECL_SIZE is integer_cst (0)

Bad.

> 3. Not call layout_decl on the template types until they are completed.

Certainly an option; not doing extra work is good.

4. Make sure that template types are incomplete.  That is, with
   TYPE_SIZE/TYPE_SIZE_UNIT unset.

A C++ front end maintainer should help choose.


r~

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

* Re: PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits
  2005-06-29 22:57 PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits Daniel Berlin
  2005-06-29 23:55 ` Richard Henderson
@ 2005-06-30 18:48 ` Giovanni Bajo
  2005-06-30 19:02   ` Daniel Berlin
  1 sibling, 1 reply; 11+ messages in thread
From: Giovanni Bajo @ 2005-06-30 18:48 UTC (permalink / raw)
  To: Daniel Berlin; +Cc: gcc, Richard Henderson

Daniel Berlin <dberlin@dberlin.org> wrote:

> So we've got a parm decl that if you ask it for the DECL_SIZE, says 0,
> but has a TYPE_SIZE of 12 bytes, and we access fields in it, etc.


I am not sure of what the exact relations between DECL_SIZE and TYPE_SIZE
are, but probably some verification could be done, eg, at gimplification
time, rather than waiting for latent bugs in optimizers to produce wrong
code?
-- 
Giovanni Bajo

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

* Re: PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits
  2005-06-30 18:48 ` Giovanni Bajo
@ 2005-06-30 19:02   ` Daniel Berlin
  0 siblings, 0 replies; 11+ messages in thread
From: Daniel Berlin @ 2005-06-30 19:02 UTC (permalink / raw)
  To: Giovanni Bajo; +Cc: gcc, Richard Henderson

On Thu, 2005-06-30 at 20:47 +0200, Giovanni Bajo wrote:
> Daniel Berlin <dberlin@dberlin.org> wrote:
> 
> > So we've got a parm decl that if you ask it for the DECL_SIZE, says 0,
> > but has a TYPE_SIZE of 12 bytes, and we access fields in it, etc.
> 
> 
> I am not sure of what the exact relations between DECL_SIZE and TYPE_SIZE
> are, but probably some verification could be done, eg, at gimplification
> time, rather than waiting for latent bugs in optimizers to produce wrong
> code?

I'll add a verify pass, but i'm sure it's going to be painful :).

--Dan

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

* Re: [C++] Re: PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits
  2005-06-30  4:35     ` [C++] " Richard Henderson
@ 2005-06-30 21:12       ` Geoffrey Keating
  2005-07-01  1:47         ` Daniel Berlin
  0 siblings, 1 reply; 11+ messages in thread
From: Geoffrey Keating @ 2005-06-30 21:12 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Gcc Mailing List

Richard Henderson <rth@redhat.com> writes:

> On Wed, Jun 29, 2005 at 09:17:07PM -0400, Daniel Berlin wrote:
> > 1. In require_complete_types_for_parms, in the C++ FE, reset DECL_SIZE
> > to NULL before we call layout_decl on the parm and let layout_decl
> > figure out what to do.
> 
> This is what relayout_decl does.
> 
> > 2. Add code in layout_decl to copy TYPE_SIZE/TYPE_SIZE_UNIT if the
> > DECL_SIZE is integer_cst (0)
> 
> Bad.
> 
> > 3. Not call layout_decl on the template types until they are completed.
> 
> Certainly an option; not doing extra work is good.
> 
> 4. Make sure that template types are incomplete.  That is, with
>    TYPE_SIZE/TYPE_SIZE_UNIT unset.

I think this makes a lot of sense considering the language semantics.
(An alternative would be to make TYPE_SIZE an expression based on the
template parameter, but that seems like a lot of work for very little
gain.)

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

* Re: [C++] Re: PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits
  2005-06-30 21:12       ` Geoffrey Keating
@ 2005-07-01  1:47         ` Daniel Berlin
  2005-07-05  6:25           ` Mark Mitchell
  0 siblings, 1 reply; 11+ messages in thread
From: Daniel Berlin @ 2005-07-01  1:47 UTC (permalink / raw)
  To: Geoffrey Keating; +Cc: Richard Henderson, Gcc Mailing List

On Thu, 2005-06-30 at 14:11 -0700, Geoffrey Keating wrote:
> Richard Henderson <rth@redhat.com> writes:
> 
> > On Wed, Jun 29, 2005 at 09:17:07PM -0400, Daniel Berlin wrote:
> > > 1. In require_complete_types_for_parms, in the C++ FE, reset DECL_SIZE
> > > to NULL before we call layout_decl on the parm and let layout_decl
> > > figure out what to do.
> > 
> > This is what relayout_decl does.
> > 
> > > 2. Add code in layout_decl to copy TYPE_SIZE/TYPE_SIZE_UNIT if the
> > > DECL_SIZE is integer_cst (0)
> > 
> > Bad.
> > 
> > > 3. Not call layout_decl on the template types until they are completed.
> > 
> > Certainly an option; not doing extra work is good.
> > 
> > 4. Make sure that template types are incomplete.  That is, with
> >    TYPE_SIZE/TYPE_SIZE_UNIT unset.
> 
> I think this makes a lot of sense considering the language semantics.

This i'm not sure how to do.
:)
I've submitted a patch for option 1 for the moment, and i'll go explore
option 4 while someone considers that (since it's blocking 22071, which
has been a regression for a few weeks now :( )



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

* Re: [C++] Re: PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits
  2005-07-01  1:47         ` Daniel Berlin
@ 2005-07-05  6:25           ` Mark Mitchell
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Mitchell @ 2005-07-05  6:25 UTC (permalink / raw)
  To: Daniel Berlin; +Cc: Geoffrey Keating, Richard Henderson, Gcc Mailing List

Daniel Berlin wrote:
> On Thu, 2005-06-30 at 14:11 -0700, Geoffrey Keating wrote:
> 

>>>Certainly an option; not doing extra work is good.
>>>
>>>4. Make sure that template types are incomplete.  That is, with
>>>   TYPE_SIZE/TYPE_SIZE_UNIT unset.
>>
>>I think this makes a lot of sense considering the language semantics.

It does not make sense to make template types incomplete, as they are in 
fact complete, and there are situations where the compiler needs to look 
inside them.  (For example, we need to look to see if there's a 
declaration of "void A<T>::f()" when we see a declaration of such a 
function.)

I'm not sure why any declaration with dependent type is ever reaching 
the middle end.  That sounds like a problem to me, unless its purely in 
the context of debugging information.

-- 
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304

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

* Re: PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits
  2005-06-30  1:17   ` Daniel Berlin
  2005-06-30  4:35     ` [C++] " Richard Henderson
@ 2005-07-05 15:35     ` Mark Mitchell
  2005-07-05 16:18       ` Daniel Berlin
  1 sibling, 1 reply; 11+ messages in thread
From: Mark Mitchell @ 2005-07-05 15:35 UTC (permalink / raw)
  To: Daniel Berlin; +Cc: Richard Henderson, Gcc Mailing List

Daniel Berlin wrote:

> 3. Not call layout_decl on the template types until they are completed.

In the abstract, this is the best choice.  Although we need to know that 
types are complete (which means (in the current implementation) that 
TYPE_SIZE != NULL_TREE), but the C++ front end should not be caring 
about DECL_SIZE on a PARM_DECL from a template.  If it is, I'd like to 
know where.

-- 
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304

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

* Re: PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits
  2005-07-05 15:35     ` Mark Mitchell
@ 2005-07-05 16:18       ` Daniel Berlin
  0 siblings, 0 replies; 11+ messages in thread
From: Daniel Berlin @ 2005-07-05 16:18 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: Richard Henderson, Gcc Mailing List

On Tue, 2005-07-05 at 08:35 -0700, Mark Mitchell wrote:
> Daniel Berlin wrote:
> 
> > 3. Not call layout_decl on the template types until they are completed.
> 
> In the abstract, this is the best choice.  Although we need to know that 
> types are complete (which means (in the current implementation) that 
> TYPE_SIZE != NULL_TREE), but the C++ front end should not be caring 
> about DECL_SIZE on a PARM_DECL from a template.  If it is, I'd like to 
> know where.

the layout_decl that sets it to size 0 gets called originally from

#0  layout_decl (decl=0x40088b64, known_align=0) at stor-layout.c:294
#1  0x085f4d51 in build_decl_stat (code=PARM_DECL, name=0x400cc208,
type=0x40088870) at tree.c:2874
#2  0x080f88c3 in cp_build_parm_decl (name=0x400cc208, type=0x40088870)
at decl2.c:141
#3  0x0807bc94 in grokdeclarator (declarator=0x898b244,
declspecs=0x898b268, decl_context=PARM, initialized=0,
attrlist=0xbfffe918)
    at decl.c:7768



IE it's getting called from common code.

Because i wasn't sure how to get around this easily, i simply went for
the easy solution :)


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

end of thread, other threads:[~2005-07-05 16:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-29 22:57 PARM_DECL of DECL_SIZE 0, but TYPE_SIZE of 96 bits Daniel Berlin
2005-06-29 23:55 ` Richard Henderson
2005-06-30  1:17   ` Daniel Berlin
2005-06-30  4:35     ` [C++] " Richard Henderson
2005-06-30 21:12       ` Geoffrey Keating
2005-07-01  1:47         ` Daniel Berlin
2005-07-05  6:25           ` Mark Mitchell
2005-07-05 15:35     ` Mark Mitchell
2005-07-05 16:18       ` Daniel Berlin
2005-06-30 18:48 ` Giovanni Bajo
2005-06-30 19:02   ` Daniel Berlin

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