[Bug c++/96776] Missing tail call optimization when passing local variable by reference to yet another function

2020-08-25 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96776

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #7 from Richard Biener  ---
.

[Bug c++/96776] Missing tail call optimization when passing local variable by reference to yet another function

2020-08-24 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96776

--- Comment #6 from Andrew Pinski  ---
(In reply to Matheus Izvekov from comment #5)
> There is one small issue with this though, but is even smaller, in that if
> foo body was visible, and it did not escape that reference further, the tail
> call would be done if foo was inlined. But if not inlined, it is not done
> regardless.

That issue is related to PR 24169; there might be others filed as well.

[Bug c++/96776] Missing tail call optimization when passing local variable by reference to yet another function

2020-08-24 Thread mizvekov at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96776

Matheus Izvekov  changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|INVALID |---

--- Comment #5 from Matheus Izvekov  ---
There is one small issue with this though, but is even smaller, in that if foo
body was visible, and it did not escape that reference further, the tail call
would be done if foo was inlined. But if not inlined, it is not done
regardless.

[Bug c++/96776] Missing tail call optimization when passing local variable by reference to yet another function

2020-08-24 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96776

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #4 from Andrew Pinski  ---
.

[Bug c++/96776] Missing tail call optimization when passing local variable by reference to yet another function

2020-08-24 Thread mizvekov at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96776

--- Comment #3 from Matheus Izvekov  ---
Yeah Andrew I realized it just after I posted, disregard.

[Bug c++/96776] Missing tail call optimization when passing local variable by reference to yet another function

2020-08-24 Thread mizvekov at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96776

Matheus Izvekov  changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|INVALID |---

--- Comment #2 from Matheus Izvekov  ---
​Oh, nevermind, scratch this issue please, I realized this is invalid anyway,
it would be legal for foo to escape that reference and expect it to live until
the end of test.

[Bug c++/96776] Missing tail call optimization when passing local variable by reference to yet another function

2020-08-24 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96776

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|--- |INVALID
 Status|UNCONFIRMED |RESOLVED

--- Comment #1 from Andrew Pinski  ---
>Calling `foo` with reference to local should not prevent tail calling `cont` 
>in this case

WRONG.

foo could store the local reference variable into a global pointer.

E.g.
static const int *a;
void foo(const int &b) noexcept
{
  a = &b;
}

void cont(void)
{
  printf(*a);
}

You can't do tail call as the argument variable escapes.