From b55c7343f02718bca7a8d2eba9dc9e6e3905d9e8 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 27 Sep 2017 16:19:57 +0200 Subject: [PATCH] re PR c++/82159 (ICE: in assign_temp, at function.c:961) PR c++/82159 * gimplify.c (gimplify_modify_expr): Don't optimize away zero sized lhs from calls if the lhs has addressable type. * g++.dg/opt/pr82159.C: New test. From-SVN: r253230 --- gcc/ChangeLog | 6 ++++++ gcc/gimplify.c | 7 ++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/opt/pr82159.C | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/opt/pr82159.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d35c497b888..44783aab64b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-09-27 Jakub Jelinek + + PR c++/82159 + * gimplify.c (gimplify_modify_expr): Don't optimize away zero sized + lhs from calls if the lhs has addressable type. + 2017-09-27 Richard Biener * graphite.h (scop::max_alias_set): New member. diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 8b29a7179c5..c3fd6ace84e 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -5479,7 +5479,12 @@ gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, side as statements and throw away the assignment. Do this after gimplify_modify_expr_rhs so we handle TARGET_EXPRs of addressable types properly. */ - if (zero_sized_type (TREE_TYPE (*from_p)) && !want_value) + if (zero_sized_type (TREE_TYPE (*from_p)) + && !want_value + /* Don't do this for calls that return addressable types, expand_call + relies on those having a lhs. */ + && !(TREE_ADDRESSABLE (TREE_TYPE (*from_p)) + && TREE_CODE (*from_p) == CALL_EXPR)) { gimplify_stmt (from_p, pre_p); gimplify_stmt (to_p, pre_p); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a61d510036c..39682ce7259 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-09-27 Jakub Jelinek + + PR c++/82159 + * g++.dg/opt/pr82159.C: New test. + 2017-09-27 Andreas Krebbel * gcc.dg/vect/pr65947-9.c: Use signed char explicitly. diff --git a/gcc/testsuite/g++.dg/opt/pr82159.C b/gcc/testsuite/g++.dg/opt/pr82159.C new file mode 100644 index 00000000000..e39dbc353fc --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr82159.C @@ -0,0 +1,18 @@ +// PR c++/82159 +// { dg-do compile } +// { dg-options "" } + +template +struct S +{ + ~S () {} + template S foo () { return S (); } + unsigned char data[N]; +}; + +int +main () +{ + S<16> d; + S<0> t = d.foo<0> (); +} -- 2.30.2