https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77938

            Bug ID: 77938
           Summary: missing tailcall optimization in case when local
                    variable escapes
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vanyacpp at gmail dot com
  Target Milestone: ---

GCC does not eliminate tailcalls in case when an address of any local variable
escapes the function. Consider the following code:

void escape(int& a);
void callee();

void caller()
{
  {
    int local;
    escape(local);
  }

  callee();
}

The variable "local" escaped, but it is dead by the time control reaches the
call to callee(). Therefore callee can not access it without invoking undefined
behavior. As the result the call to callee() can be a tailcall.

Reply via email to