From: Jakub Jelinek Date: Mon, 25 Jun 2018 16:43:16 +0000 (+0200) Subject: backport: re PR c++/82159 (ICE: in assign_temp, at function.c:961) X-Git-Tag: releases/gcc-6.5.0~256 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3acfb0be47f1ee8d881d5ce5adf835b032ad53d8;p=thirdparty%2Fgcc.git backport: re PR c++/82159 (ICE: in assign_temp, at function.c:961) Backported from mainline 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. * g++.dg/opt/pr82159.C: New test. From-SVN: r262026 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3ec50a873c00..62309f352e26 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2018-06-25 Jakub Jelinek + + Backported from mainline + 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. + 2018-06-23 Richard Sandiford PR tree-optimization/85989 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 450c061011b6..e55f5b4216dd 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -4696,7 +4696,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 4b40b0e5631b..2404a59569a6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2018-06-25 Jakub Jelinek + + Backported from mainline + 2017-09-27 Jakub Jelinek + + PR c++/82159 + * g++.dg/opt/pr82159.C: New test. + 2018-06-23 Richard Sandiford PR tree-optimization/85989 diff --git a/gcc/testsuite/g++.dg/opt/pr82159.C b/gcc/testsuite/g++.dg/opt/pr82159.C new file mode 100644 index 000000000000..e39dbc353fc1 --- /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> (); +}