Message ID | 20170927132444.GW1701@tucnak |
---|---|
State | New |
Headers | show |
Series | Don't optimize away lhs from calls with addressable zero sized return type (PR c++/82159) | expand |
On Wed, 27 Sep 2017, Jakub Jelinek wrote: > Hi! > > The expansion relies on lhs being kept for calls that return addressable > types. On the following testcase (which is a GNU extension, pedantically > we error out on zero sized arrays) we return TREE_ADDRESSABLE > zero_sized_type and optimize away the lhs which we need later on. > > Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, > during the bootstrap+regtests it only made a difference on the newly added > testcase. Ok for trunk? Ok. Thanks, Richard. > 2017-09-27 Jakub Jelinek <jakub@redhat.com> > > 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. > > --- gcc/gimplify.c.jj 2017-09-01 09:25:34.000000000 +0200 > +++ gcc/gimplify.c 2017-09-26 13:03:11.614726601 +0200 > @@ -5479,7 +5479,12 @@ gimplify_modify_expr (tree *expr_p, gimp > 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); > --- gcc/testsuite/g++.dg/opt/pr82159.C.jj 2017-09-26 13:04:08.711027279 +0200 > +++ gcc/testsuite/g++.dg/opt/pr82159.C 2017-09-26 14:20:01.519361945 +0200 > @@ -0,0 +1,18 @@ > +// PR c++/82159 > +// { dg-do compile } > +// { dg-options "" } > + > +template<int N> > +struct S > +{ > + ~S () {} > + template<int M> S<M> foo () { return S<M> (); } > + unsigned char data[N]; > +}; > + > +int > +main () > +{ > + S<16> d; > + S<0> t = d.foo<0> (); > +} > > Jakub > >
--- gcc/gimplify.c.jj 2017-09-01 09:25:34.000000000 +0200 +++ gcc/gimplify.c 2017-09-26 13:03:11.614726601 +0200 @@ -5479,7 +5479,12 @@ gimplify_modify_expr (tree *expr_p, gimp 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); --- gcc/testsuite/g++.dg/opt/pr82159.C.jj 2017-09-26 13:04:08.711027279 +0200 +++ gcc/testsuite/g++.dg/opt/pr82159.C 2017-09-26 14:20:01.519361945 +0200 @@ -0,0 +1,18 @@ +// PR c++/82159 +// { dg-do compile } +// { dg-options "" } + +template<int N> +struct S +{ + ~S () {} + template<int M> S<M> foo () { return S<M> (); } + unsigned char data[N]; +}; + +int +main () +{ + S<16> d; + S<0> t = d.foo<0> (); +}