On Wed, Dec 05, 2018 at 09:50:56PM +0100, Jakub Jelinek wrote: > On Wed, Dec 05, 2018 at 03:49:26PM -0500, Jason Merrill wrote: > > On 11/28/18 3:42 AM, Jakub Jelinek wrote: > > > Whenever we need to clone a cdtor (either because the target doesn't > > > support > > > aliases the way we need, e.g. initlist105.C testcase on darwin, where it > > > has > > > been originally reported, or when it has virtual bases, like the made up > > > initlist106.C on x86_64-linux), we rely on DECL_INITIAL of the local > > > variables being unshared, because the tree unsharing gimplify.c performs > > > doesn't unshare DECL_INITIAL. clone_body has some code to recurse on the > > > DECL_INITIAL, but it handles just decls FOR_EACH_LOCAL_DECL walks. I > > > believe it is generally ok that not all temporaries are covered in local > > > decls, the gimplifier should take care of those fine if we don't need > > > debug info for them. > > > > I think any temporaries that have DECL_INITIAL should be pushed so that they > > end up in local_decls. set_up_extended_ref_temp already adds a DECL_EXPR > > for it, I guess we need a pushdecl as well. Though the comment for > > get_temp_regvar suggests that this is problematic somehow. > > Ok, will play with it tomorrow.
The following fixes the testcase too and passed bootstrap/regtest on x86_64-linux and i686-linux, ok for trunk? 2018-12-07 Jakub Jelinek <ja...@redhat.com> PR c++/86669 * call.c (make_temporary_var_for_ref_to_temp): Call pushdecl even for automatic vars. * g++.dg/cpp0x/initlist105.C: New test. * g++.dg/cpp0x/initlist106.C: New test. * g++.dg/other/pr86669.C: New test. --- gcc/cp/call.c.jj 2018-11-29 23:11:38.386646583 +0100 +++ gcc/cp/call.c 2018-12-06 13:50:26.766178596 +0100 @@ -11130,14 +11130,12 @@ make_temporary_var_for_ref_to_temp (tree tree name = mangle_ref_init_variable (decl); DECL_NAME (var) = name; SET_DECL_ASSEMBLER_NAME (var, name); - - var = pushdecl (var); } else /* Create a new cleanup level if necessary. */ maybe_push_cleanup_level (type); - return var; + return pushdecl (var); } /* EXPR is the initializer for a variable DECL of reference or --- gcc/testsuite/g++.dg/cpp0x/initlist105.C.jj 2018-12-06 13:31:35.993609689 +0100 +++ gcc/testsuite/g++.dg/cpp0x/initlist105.C 2018-12-06 13:31:35.993609689 +0100 @@ -0,0 +1,28 @@ +// PR c++/86669 +// { dg-do run { target c++11 } } + +#include <initializer_list> + +struct S { S (); }; +struct T : public S {}; +int cnt; +void foo (int) { cnt++; } + +S::S () +{ + int e = 1, f = 2, g = 3, h = 4; + + for (auto k : { e, f, g, h }) + foo (k); +} + +int +main () +{ + S s; + if (cnt != 4) + __builtin_abort (); + T t; + if (cnt != 8) + __builtin_abort (); +} --- gcc/testsuite/g++.dg/cpp0x/initlist106.C.jj 2018-12-06 13:31:35.993609689 +0100 +++ gcc/testsuite/g++.dg/cpp0x/initlist106.C 2018-12-06 13:31:35.993609689 +0100 @@ -0,0 +1,29 @@ +// PR c++/86669 +// { dg-do run { target c++11 } } + +#include <initializer_list> + +struct A { }; +struct S : virtual public A { S (); }; +struct T : public S, virtual public A {}; +int cnt; +void foo (int) { cnt++; } + +S::S () +{ + int e = 1, f = 2, g = 3, h = 4; + + for (auto k : { e, f, g, h }) + foo (k); +} + +int +main () +{ + S s; + if (cnt != 4) + __builtin_abort (); + T t; + if (cnt != 8) + __builtin_abort (); +} --- gcc/testsuite/g++.dg/other/pr86669.C.jj 2018-12-06 13:31:35.993609689 +0100 +++ gcc/testsuite/g++.dg/other/pr86669.C 2018-12-06 13:31:35.993609689 +0100 @@ -0,0 +1,10 @@ +// PR c++/86669 +// { dg-do compile } + +struct S { S (); }; +struct T : public S {}; + +S::S () +{ + int *p = { (int *) &p }; +} Jakub