Re: [C++ PATCH] Fix ICE with bitfields (PR c++/69164, take 2)
OK. Jason
[C++ PATCH] Fix ICE with bitfields (PR c++/69164, take 2)
On Fri, Jan 08, 2016 at 09:02:34AM -0500, Jason Merrill wrote: > On 01/08/2016 07:58 AM, Jakub Jelinek wrote: > >On Fri, Jan 08, 2016 at 01:46:47PM +0100, Bernd Schmidt wrote: > >>On 01/07/2016 10:43 PM, Jakub Jelinek wrote: > >>> > >>> PR c++/69164 > >>> * class.c (layout_class_type): Also copy DEC_SIZE_UNIT, DECL_BIT_FIELD > >>> and DEC_BIT_FIELD_TYPE. > >> > >>Any reason this isn't using copy_node? > > > >No idea, perhaps that would be even better. Jason? > > I imagine that the code is trying to avoid copying lang-specific information > to the artificial as-base type, but I don't see why copying that would be a > problem. Try copy_node and see if anything breaks? This passed bootstrap/regtest on x86_64-linux and i686-linux, ok for trunk? 2016-01-08 Jakub Jelinek PR c++/69164 * class.c (layout_class_type): Use copy_node to copy FIELD_DECLs. * g++.dg/opt/pr69164.C: New test. --- gcc/cp/class.c.jj 2016-01-08 07:31:08.687172019 +0100 +++ gcc/cp/class.c 2016-01-08 15:16:49.946359971 +0100 @@ -6484,18 +6484,11 @@ layout_class_type (tree t, tree *virtual for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field)) if (TREE_CODE (field) == FIELD_DECL) { - *next_field = build_decl (input_location, - FIELD_DECL, - DECL_NAME (field), - TREE_TYPE (field)); + *next_field = copy_node (field); DECL_CONTEXT (*next_field) = base_t; - DECL_FIELD_OFFSET (*next_field) = DECL_FIELD_OFFSET (field); - DECL_FIELD_BIT_OFFSET (*next_field) - = DECL_FIELD_BIT_OFFSET (field); - DECL_SIZE (*next_field) = DECL_SIZE (field); - DECL_MODE (*next_field) = DECL_MODE (field); next_field = &DECL_CHAIN (*next_field); } + *next_field = NULL_TREE; /* Record the base version of the type. */ CLASSTYPE_AS_BASE (t) = base_t; --- gcc/testsuite/g++.dg/opt/pr69164.C.jj 2016-01-08 15:14:43.769109468 +0100 +++ gcc/testsuite/g++.dg/opt/pr69164.C 2016-01-08 15:14:43.769109468 +0100 @@ -0,0 +1,30 @@ +// PR c++/69164 +// { dg-do compile { target c++11 } } +// { dg-options "-O2" } + +struct A { + struct B { +B () {} +bool : 1; + }; + B foo () { B r; return r; } +}; + +struct C { + struct D { +D (C *x) : d (x->c.foo ()) {} +A::B d; + }; + A c; +}; + +struct F : C { + D f = this; + F (int, int) {} +}; + +void +bar (int a, int b) +{ + F (b, a); +} Jakub
Re: [C++ PATCH] Fix ICE with bitfields (PR c++/69164)
On 01/08/2016 07:58 AM, Jakub Jelinek wrote: On Fri, Jan 08, 2016 at 01:46:47PM +0100, Bernd Schmidt wrote: On 01/07/2016 10:43 PM, Jakub Jelinek wrote: PR c++/69164 * class.c (layout_class_type): Also copy DEC_SIZE_UNIT, DECL_BIT_FIELD and DEC_BIT_FIELD_TYPE. Any reason this isn't using copy_node? No idea, perhaps that would be even better. Jason? I imagine that the code is trying to avoid copying lang-specific information to the artificial as-base type, but I don't see why copying that would be a problem. Try copy_node and see if anything breaks? Jason
Re: [C++ PATCH] Fix ICE with bitfields (PR c++/69164)
On Fri, Jan 08, 2016 at 01:46:47PM +0100, Bernd Schmidt wrote: > On 01/07/2016 10:43 PM, Jakub Jelinek wrote: > > > > PR c++/69164 > > * class.c (layout_class_type): Also copy DEC_SIZE_UNIT, DECL_BIT_FIELD > > and DEC_BIT_FIELD_TYPE. > > Any reason this isn't using copy_node? No idea, perhaps that would be even better. Jason? Jakub
Re: [C++ PATCH] Fix ICE with bitfields (PR c++/69164)
On 01/07/2016 10:43 PM, Jakub Jelinek wrote: PR c++/69164 * class.c (layout_class_type): Also copy DEC_SIZE_UNIT, DECL_BIT_FIELD and DEC_BIT_FIELD_TYPE. Any reason this isn't using copy_node? Bernd
[C++ PATCH] Fix ICE with bitfields (PR c++/69164)
Hi! We ICE on the following testcase during SRA, because it sees a field with DECL_SIZE of 1 which is not DECL_BIT_FIELD. The problem is that layout_class_type in some cases copies fields, including DECL_SIZE, but does not copy over DECL_BIT_FIELD flag. The following patch copies even that and also DECL_SIZE_UNIT and DEC_BIT_FIELD_TYPE that weren't copied either. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-01-07 Jakub Jelinek PR c++/69164 * class.c (layout_class_type): Also copy DEC_SIZE_UNIT, DECL_BIT_FIELD and DEC_BIT_FIELD_TYPE. * g++.dg/opt/pr69164.C: New test. --- gcc/cp/class.c.jj 2016-01-04 14:55:57.0 +0100 +++ gcc/cp/class.c 2016-01-07 13:59:13.895677297 +0100 @@ -6493,7 +6493,10 @@ layout_class_type (tree t, tree *virtual DECL_FIELD_BIT_OFFSET (*next_field) = DECL_FIELD_BIT_OFFSET (field); DECL_SIZE (*next_field) = DECL_SIZE (field); + DECL_SIZE_UNIT (*next_field) = DECL_SIZE_UNIT (field); DECL_MODE (*next_field) = DECL_MODE (field); + DECL_BIT_FIELD (*next_field) = DECL_BIT_FIELD (field); + DECL_BIT_FIELD_TYPE (*next_field) = DECL_BIT_FIELD_TYPE (field); next_field = &DECL_CHAIN (*next_field); } --- gcc/testsuite/g++.dg/opt/pr69164.C.jj 2016-01-07 13:56:33.013915214 +0100 +++ gcc/testsuite/g++.dg/opt/pr69164.C 2016-01-07 13:55:57.0 +0100 @@ -0,0 +1,30 @@ +// PR c++/69164 +// { dg-do compile { target c++11 } } +// { dg-options "-O2" } + +struct A { + struct B { +B () {} +bool : 1; + }; + B foo () { B r; return r; } +}; + +struct C { + struct D { +D (C *x) : d (x->c.foo ()) {} +A::B d; + }; + A c; +}; + +struct F : C { + D f = this; + F (int, int) {} +}; + +void +bar (int a, int b) +{ + F (b, a); +} Jakub