From 60a2c64519087972b16d94f6cca209fa6a3f0940 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 12 Apr 2019 23:45:54 +0200 Subject: [PATCH] re PR c/89933 (ICE in merge_decls, at c/c-decl.c:2517) PR c/89933 c/ * c-decl.c (merge_decls): When newdecl's type is its main variant, don't try to remove it from the variant list, but instead assert it has no variants. cp/ * decl.c (duplicate_decls): When newdecl's type is its main variant, don't try to remove it from the variant list, but instead assert it has no variants. testsuite/ * c-c++-common/pr89933.c: New test. From-SVN: r270329 --- gcc/c/ChangeLog | 7 +++++++ gcc/c/c-decl.c | 17 ++++++++++------- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/decl.c | 17 ++++++++++------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/pr89933.c | 5 +++++ 6 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/pr89933.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 076a9a26501..c8e5e1a6b0b 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,10 @@ +2019-04-12 Jakub Jelinek + + PR c/89933 + * c-decl.c (merge_decls): When newdecl's type is its main variant, + don't try to remove it from the variant list, but instead assert + it has no variants. + 2019-04-01 Richard Biener PR c/71598 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 8d5c35ab475..ef9b874f997 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -2512,13 +2512,16 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype) if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl) { tree remove = TREE_TYPE (newdecl); - for (tree t = TYPE_MAIN_VARIANT (remove); ; - t = TYPE_NEXT_VARIANT (t)) - if (TYPE_NEXT_VARIANT (t) == remove) - { - TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove); - break; - } + if (TYPE_MAIN_VARIANT (remove) == remove) + gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE); + else + for (tree t = TYPE_MAIN_VARIANT (remove); ; + t = TYPE_NEXT_VARIANT (t)) + if (TYPE_NEXT_VARIANT (t) == remove) + { + TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove); + break; + } } } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 212318e0966..67baed6672f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2019-04-12 Jakub Jelinek + + PR c/89933 + * decl.c (duplicate_decls): When newdecl's type is its main variant, + don't try to remove it from the variant list, but instead assert + it has no variants. + 2019-04-12 Martin Sebor PR c/88383 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 2528a8cd670..67d9244c450 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -2132,13 +2132,16 @@ next_arg:; if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl) { tree remove = TREE_TYPE (newdecl); - for (tree t = TYPE_MAIN_VARIANT (remove); ; - t = TYPE_NEXT_VARIANT (t)) - if (TYPE_NEXT_VARIANT (t) == remove) - { - TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove); - break; - } + if (TYPE_MAIN_VARIANT (remove) == remove) + gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE); + else + for (tree t = TYPE_MAIN_VARIANT (remove); ; + t = TYPE_NEXT_VARIANT (t)) + if (TYPE_NEXT_VARIANT (t) == remove) + { + TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove); + break; + } } } else if (merge_attr) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ed6f731b5b5..2951fc82167 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-04-12 Jakub Jelinek + + PR c/89933 + * c-c++-common/pr89933.c: New test. + 2019-04-12 Martin Sebor PR c/88383 diff --git a/gcc/testsuite/c-c++-common/pr89933.c b/gcc/testsuite/c-c++-common/pr89933.c new file mode 100644 index 00000000000..870504d4208 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr89933.c @@ -0,0 +1,5 @@ +/* PR c/89933 */ +/* { dg-do compile } */ + +typedef unsigned int a __attribute__ ((__aligned__(8), __may_alias__)); +typedef unsigned int a __attribute__ ((__aligned__(8), __may_alias__)); -- 2.30.2