From 423aec8b5756c73681dadd10aec25e28dc18eb99 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 9 Mar 2017 08:35:37 +0000 Subject: [PATCH] PR c++/79900 - ICE in strip_typedefs 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. From-SVN: r245988 --- gcc/cp/ChangeLog | 6 ++++ gcc/cp/tree.c | 47 +++++++++++++++++---------- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/g++.dg/warn/Wpadded-1.C | 22 +++++++++++++ 4 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wpadded-1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5bd83227ff7..caf0322972f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-03-09 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. + 2017-03-08 Jason Merrill PR c++/79797 - ICE with self-reference in array DMI. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index d3c63b82cb3..2757af6691d 100644 --- a/gcc/cp/tree.c +++ b/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 a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 396ab3ad121..6c8ab1d87fb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-03-09 Marek Polacek + + PR c++/79900 - ICE in strip_typedefs + * g++.dg/warn/Wpadded-1.C: New test. + 2017-03-08 Marek Polacek * g++.dg/Walloca1.C: Adjust dg-warning. diff --git a/gcc/testsuite/g++.dg/warn/Wpadded-1.C b/gcc/testsuite/g++.dg/warn/Wpadded-1.C new file mode 100644 index 00000000000..b3f058135ff --- /dev/null +++ b/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; } -- 2.30.2