This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH to fix ICE in strip_typedefs with -Wpadded (PR c++/79900)
- From: Marek Polacek <polacek at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Thu, 9 Mar 2017 23:32:31 +0100
- Subject: Re: C++ PATCH to fix ICE in strip_typedefs with -Wpadded (PR c++/79900)
- Authentication-results: sourceware.org; auth=none
- References: <20170308230048.GA3172@redhat.com> <20170309210653.GK22703@tucnak>
On Thu, Mar 09, 2017 at 10:06:53PM +0100, Jakub Jelinek wrote:
> On Thu, Mar 09, 2017 at 12:00:48AM +0100, Marek Polacek wrote:
> > We crash on an assert in strip_typedefs, because we find ourselves in a
> > scenario where RESULT, the main variant of a struct, was modified in
> > finalize_record_size (its TYPE_ALIGN changed), but its variants (T in
> > strip_typedefs) weren't fixed-up yet; that will happen slightly later in
> > finalize_type_size. So there's a discrepancy that confuses the code.
> >
> > This patch implements what Jason suggested to me on IRC, i.e., skip the
> > attribute handling if RESULT is complete and T isn't.
> >
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> >
> > 2017-03-08 Marek Polacek <polacek@redhat.com>
> >
> > PR c++/79900 - ICE in strip_typedefs
> > * tree.c (strip_typedefs): Skip the attribute handling if T is
> > a variant type which hasn't been updated yet.
> >
> > * g++.dg/warn/Wpadded-1.C: New test.
> >
> > diff --git gcc/testsuite/g++.dg/warn/Wpadded-1.C gcc/testsuite/g++.dg/warn/Wpadded-1.C
> > index e69de29..b3f0581 100644
> > --- gcc/testsuite/g++.dg/warn/Wpadded-1.C
> > +++ gcc/testsuite/g++.dg/warn/Wpadded-1.C
> > @@ -0,0 +1,22 @@
> > +// PR c++/79900 - ICE in strip_typedefs
> > +// { dg-do compile }
> > +// { dg-options "-Wpadded" }
> > +
> > +template <class> struct A;
> > +template <typename> struct B { // { dg-warning "padding struct size to alignment boundary" }
> > + long _M_off;
> > + int _M_state;
> > +};
>
> This fails on i686-linux, there is obviously no padding of struct size to
> alignment boundary in that case.
Ah, of course...
> Can't _M_state be e.g. char, then it would work at least on all targets
> where long has alignment of at least 2 (that can be all of them)?
> Perhaps also make _M_off long long or add a double or long double field.
Like this? Passes with -m32.
2017-03-09 Marek Polacek <polacek@redhat.com>
* g++.dg/warn/Wpadded-1.C: Change types of struct B fields.
diff --git gcc/testsuite/g++.dg/warn/Wpadded-1.C gcc/testsuite/g++.dg/warn/Wpadded-1.C
index b3f0581..af375a4 100644
--- gcc/testsuite/g++.dg/warn/Wpadded-1.C
+++ gcc/testsuite/g++.dg/warn/Wpadded-1.C
@@ -4,8 +4,8 @@
template <class> struct A;
template <typename> struct B { // { dg-warning "padding struct size to alignment boundary" }
- long _M_off;
- int _M_state;
+ long long _M_off;
+ char _M_state;
};
template <> struct A<char> { typedef B<int> pos_type; };
enum _Ios_Openmode {};
Marek