From 97fabbc141bc3fd97a10205a062620f5cccab0c9 Mon Sep 17 00:00:00 2001 From: jakub Date: Thu, 12 Oct 2017 07:23:24 +0000 Subject: [PATCH] PR c++/82159 * expr.c (store_field): Don't optimize away bitsize == 0 store from CALL_EXPR with addressable return type. * g++.dg/opt/pr82159-2.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253673 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++ gcc/expr.c | 7 ++-- gcc/testsuite/ChangeLog | 3 ++ gcc/testsuite/g++.dg/opt/pr82159-2.C | 65 ++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/opt/pr82159-2.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 40fa8f5a2e6..12cf2d30475 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-10-12 Jakub Jelinek + + PR c++/82159 + * expr.c (store_field): Don't optimize away bitsize == 0 store + from CALL_EXPR with addressable return type. + 2017-10-11 Segher Boessenkool * config/rs6000/rs6000.h (TARGET_ISEL64): Delete. diff --git a/gcc/expr.c b/gcc/expr.c index d2e4d042f1b..1bba9330cd3 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -6749,8 +6749,11 @@ store_field (rtx target, HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos, return const0_rtx; /* If we have nothing to store, do nothing unless the expression has - side-effects. */ - if (bitsize == 0) + side-effects. Don't do that for zero sized addressable lhs of + calls. */ + if (bitsize == 0 + && (!TREE_ADDRESSABLE (TREE_TYPE (exp)) + || TREE_CODE (exp) != CALL_EXPR)) return expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL); if (GET_CODE (target) == CONCAT) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c0d873daf0f..eaf1ce59531 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-10-12 Jakub Jelinek + PR c++/82159 + * g++.dg/opt/pr82159-2.C: New test. + PR target/82353 * gcc.target/i386/i386.exp (tests): Revert the '.C' extension change. * gcc.target/i386/pr82353.C: Moved to ... diff --git a/gcc/testsuite/g++.dg/opt/pr82159-2.C b/gcc/testsuite/g++.dg/opt/pr82159-2.C new file mode 100644 index 00000000000..f153c29ddac --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr82159-2.C @@ -0,0 +1,65 @@ +// PR c++/82159 +// { dg-do compile } +// { dg-options "" } + +template struct D { T e; }; +struct F : D { + F(const F &); +}; +struct G : F { + template G operator-(T); +}; +template struct I { + typedef typename T::template J ak; +}; +template struct K { typename I::ak an; }; +struct H { + G l; +}; +struct C { + ~C(); +}; +template struct M : T { + template M(U, V); + H h; + virtual void foo() { T::bar(&h); } +}; +template class A; +template struct B { + typedef int BT; + struct BC {}; + template struct BD { + G g; + BD(BT, T n) : g(n.l - 0) {} + }; + B(BT, BC); +}; +template struct O; +template +struct O > > : public B >::BC {}; +struct L : B > { + struct P : C { + void bar(H *x) { + BT a; + BD(a, *x); + } + }; + template L(U x, V n) : B(x, n) {} + int ll; + virtual int baz() { M

(this, ll); } +}; +template class Q { + O > > q; + virtual L baz() { L(0, q); } +}; +template