From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20849 invoked by alias); 9 Mar 2017 00:52:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 20832 invoked by uid 89); 9 Mar 2017 00:52:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy=Hx-languages-length:3853 X-HELO: mail-ot0-f169.google.com Received: from mail-ot0-f169.google.com (HELO mail-ot0-f169.google.com) (74.125.82.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 09 Mar 2017 00:52:51 +0000 Received: by mail-ot0-f169.google.com with SMTP id o24so46634270otb.1 for ; Wed, 08 Mar 2017 16:52:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=vkXTJrWNk8Hw+uNZvmeX+m87+Eyzs0RBtqiE7DrJHME=; b=gLhTzDF0ilKhlsJ9rbcl0+1N+9UhEFlCmyO1kw6zVWkM/uWqtpH0ufLykFBtrKNrWN HPSPAg6h5mR7BP3zCcG/lkwAebFW3awwPwxz4KwldbmApzXn0E1qEwW/i49aikJiEJP8 G7DqeGG20OMQ59IYcevkWxQ5H5XFKiUQyjFZAGdiC+t3PjoGw2Oo1vWNJpPYNnhQlwXA bbVp8tX+IvqECukyUsCd9ucgX8rvT8zeWHeyCv7NKnSS/knU0u0nCGiVkHr1GctIONSU IYynEkidrGlWqmH9/okxDBtDs7cGyeP8MgV6Li3KoKx1fBaCNEE9rLqJEz08SA2lr8nb kH2g== X-Gm-Message-State: AMke39mHEw5evAxZgQH9PO17PIR+ulwiiZjSN5kB1I7ZJkT9QieK1hciUhCaB0hvpq2aQ8RrD/1jZWyIIS/s1Uvu X-Received: by 10.157.61.164 with SMTP id l33mr5904160otc.274.1489020770635; Wed, 08 Mar 2017 16:52:50 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.187.8 with HTTP; Wed, 8 Mar 2017 16:52:30 -0800 (PST) In-Reply-To: <20170308230048.GA3172@redhat.com> References: <20170308230048.GA3172@redhat.com> From: Jason Merrill Date: Thu, 09 Mar 2017 00:52:00 -0000 Message-ID: Subject: Re: C++ PATCH to fix ICE in strip_typedefs with -Wpadded (PR c++/79900) To: Marek Polacek Cc: GCC Patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2017-03/txt/msg00389.txt.bz2 OK. On Wed, Mar 8, 2017 at 6:00 PM, 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 > > 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/cp/tree.c gcc/cp/tree.c > index d3c63b8..b3a4a10 100644 > --- gcc/cp/tree.c > +++ gcc/cp/tree.c > @@ -1548,29 +1548,40 @@ strip_typedefs (tree t, bool *remove_attributes) > result = TYPE_MAIN_VARIANT (t); > } > gcc_assert (!typedef_variant_p (result)); > - if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result) > - || TYPE_ALIGN (t) != TYPE_ALIGN (result)) > + > + if (COMPLETE_TYPE_P (result) && !COMPLETE_TYPE_P (t)) > + /* If RESULT is complete and T isn't, it's likely the case that T > + is a variant of RESULT which hasn't been updated yet. Skip the > + attribute handling. */; > + else > { > - gcc_assert (TYPE_USER_ALIGN (t)); > - if (remove_attributes) > - *remove_attributes = true; > - else > + if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result) > + || TYPE_ALIGN (t) != TYPE_ALIGN (result)) > { > - if (TYPE_ALIGN (t) == TYPE_ALIGN (result)) > - result = build_variant_type_copy (result); > + gcc_assert (TYPE_USER_ALIGN (t)); > + if (remove_attributes) > + *remove_attributes = true; > else > - result = build_aligned_type (result, TYPE_ALIGN (t)); > - TYPE_USER_ALIGN (result) = true; > + { > + if (TYPE_ALIGN (t) == TYPE_ALIGN (result)) > + result = build_variant_type_copy (result); > + else > + result = build_aligned_type (result, TYPE_ALIGN (t)); > + TYPE_USER_ALIGN (result) = true; > + } > + } > + > + if (TYPE_ATTRIBUTES (t)) > + { > + if (remove_attributes) > + result = apply_identity_attributes (result, TYPE_ATTRIBUTES (t), > + remove_attributes); > + else > + result = cp_build_type_attribute_variant (result, > + TYPE_ATTRIBUTES (t)); > } > } > - if (TYPE_ATTRIBUTES (t)) > - { > - if (remove_attributes) > - result = apply_identity_attributes (result, TYPE_ATTRIBUTES (t), > - remove_attributes); > - else > - result = cp_build_type_attribute_variant (result, TYPE_ATTRIBUTES (t)); > - } > + > return cp_build_qualified_type (result, cp_type_quals (t)); > } > > 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 struct A; > +template struct B { // { dg-warning "padding struct size to alignment boundary" } > + long _M_off; > + int _M_state; > +}; > +template <> struct A { typedef B pos_type; }; > +enum _Ios_Openmode {}; > +struct C { > + typedef _Ios_Openmode openmode; > +}; > +template struct D { > + typedef typename _Traits::pos_type pos_type; > + pos_type m_fn1(pos_type, C::openmode); > +}; > +template class D >; > +template > +typename D<_CharT, _Traits>::pos_type D<_CharT, _Traits>::m_fn1(pos_type x, > + C::openmode) { return x; } > > Marek