[Bug c++/100468] set_up_extended_ref_temp via extend_ref_init_temps_1 drops TREE_ADDRESSABLE
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100468 --- Comment #7 from CVS Commits --- The releases/gcc-11 branch has been updated by Richard Biener : https://gcc.gnu.org/g:462900ba21f5fdf865c93f693083da3179dd3151 commit r11-9591-g462900ba21f5fdf865c93f693083da3179dd3151 Author: Richard Biener Date: Fri May 7 09:51:18 2021 +0200 middle-end/100464 - avoid spurious TREE_ADDRESSABLE in folding debug stmts canonicalize_constructor_val was setting TREE_ADDRESSABLE on bases of ADDR_EXPRs but that's futile when we're dealing with CTOR values in debug stmts. This rips out the code which was added for Java and should have been an assertion when we didn't have debug stmts. To not regress g++.dg/tree-ssa/array-temp1.C we have to adjust the testcase to not look for a no longer applied invalid optimization. 2021-05-10 Richard Biener PR middle-end/100464 PR c++/100468 gcc/ * gimple-fold.c (canonicalize_constructor_val): Do not set TREE_ADDRESSABLE. gcc/cp/ * call.c (set_up_extended_ref_temp): Mark the temporary addressable if the TARGET_EXPR was. gcc/testsuite/ * gcc.dg/pr100464.c: New testcase. * g++.dg/tree-ssa/array-temp1.C: Adjust. (cherry picked from commit a076632e274abe344ca7648b7c7f299273d4cbe0)
[Bug c++/100468] set_up_extended_ref_temp via extend_ref_init_temps_1 drops TREE_ADDRESSABLE
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100468 --- Comment #6 from CVS Commits --- The master branch has been updated by Richard Biener : https://gcc.gnu.org/g:a076632e274abe344ca7648b7c7f299273d4cbe0 commit r12-657-ga076632e274abe344ca7648b7c7f299273d4cbe0 Author: Richard Biener Date: Fri May 7 09:51:18 2021 +0200 middle-end/100464 - avoid spurious TREE_ADDRESSABLE in folding debug stmts canonicalize_constructor_val was setting TREE_ADDRESSABLE on bases of ADDR_EXPRs but that's futile when we're dealing with CTOR values in debug stmts. This rips out the code which was added for Java and should have been an assertion when we didn't have debug stmts. To not regress g++.dg/tree-ssa/array-temp1.C we have to adjust the testcase to not look for a no longer applied invalid optimization. 2021-05-10 Richard Biener PR middle-end/100464 PR c++/100468 gcc/ * gimple-fold.c (canonicalize_constructor_val): Do not set TREE_ADDRESSABLE. gcc/cp/ * call.c (set_up_extended_ref_temp): Mark the temporary addressable if the TARGET_EXPR was. gcc/testsuite/ * gcc.dg/pr100464.c: New testcase. * g++.dg/tree-ssa/array-temp1.C: Adjust.
[Bug c++/100468] set_up_extended_ref_temp via extend_ref_init_temps_1 drops TREE_ADDRESSABLE
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100468 --- Comment #5 from Jakub Jelinek --- Though it is static and what you're talking about is making automatic into static. So guess we would need automatic temporary with something like { 1, 2, 3 } initializer and have reference bind to that temporary. My C++-fu is limited.
[Bug c++/100468] set_up_extended_ref_temp via extend_ref_init_temps_1 drops TREE_ADDRESSABLE
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100468 --- Comment #4 from Jakub Jelinek --- I meant something like struct S { constexpr S () : s (0), t (0), u(0) {} constexpr S (int x, int y, int z) : s (x), t (y), u (z) {} int s, t, u; }; constexpr S bar () { return S (0, 1, 2); } bool foo (void) { constexpr static const S&& a = bar (); constexpr static const S&& b = bar (); return == } int main () { if (foo ()) __builtin_abort (); } but haven't tried your patch to see if it triggers. I certainly see static const struct S & a = (const struct S &) &_ZGRZ3foovE1a_; static struct S _ZGRZ3foovE1a_ = {.s=0, .t=1, .u=2}; static const struct S & b = (const struct S &) &_ZGRZ3foovE1b_; static struct S _ZGRZ3foovE1b_ = {.s=0, .t=1, .u=2}; in the gimple dump and I believe the _ZGRZ3foovE1*_ vars are DECL_ARTIFICIAL.
[Bug c++/100468] set_up_extended_ref_temp via extend_ref_init_temps_1 drops TREE_ADDRESSABLE
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100468 --- Comment #3 from rguenther at suse dot de --- On Fri, 7 May 2021, jakub at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100468 > > Jakub Jelinek changed: > >What|Removed |Added > > CC||jakub at gcc dot gnu.org > > --- Comment #2 from Jakub Jelinek --- > What I fear is that we have some temporary with a const initializer, extend > its > lifetime by taking a reference, have another temporary with the same const > initializer, extend its lifetime by taking a reference and compare the > addresses of those two references. As those are different temporaries, their > addresses should be different, shouldn't they? If you're thinking of a specific case maybe you can come up with a testcase we can add? The testsuite comes out clean with the suggested change.
[Bug c++/100468] set_up_extended_ref_temp via extend_ref_init_temps_1 drops TREE_ADDRESSABLE
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100468 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #2 from Jakub Jelinek --- What I fear is that we have some temporary with a const initializer, extend its lifetime by taking a reference, have another temporary with the same const initializer, extend its lifetime by taking a reference and compare the addresses of those two references. As those are different temporaries, their addresses should be different, shouldn't they?
[Bug c++/100468] set_up_extended_ref_temp via extend_ref_init_temps_1 drops TREE_ADDRESSABLE
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100468 Richard Biener changed: What|Removed |Added CC||jason at gcc dot gnu.org --- Comment #1 from Richard Biener --- The bug also causes g++.dg/tree-ssa/array-temp1.C to pass, notably the gimplifiers gimplify_init_constructor to pass the && (flag_merge_constants >= 2 || !TREE_ADDRESSABLE (object)) test even though clearly the variable is address-taken, resulting in static const int C.1[3] = {1, 42, 3}; try { a = {}; a._M_len = 3; a._M_array = _1 = std::initializer_list::begin (); I was tempted to add a || DECL_ARTIFICIAL (object) but Jakub says that's probably not good.