Reject tail calls that read from an escaped RESULT_DECL (PR90313)
authorRichard Sandiford <richard.sandiford@arm.com>
Fri, 9 Aug 2019 09:37:55 +0000 (09:37 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Fri, 9 Aug 2019 09:37:55 +0000 (09:37 +0000)
commit97bf048c04d93ba1e0265893fdb06f8991c149f7
treea9411dc3fa2b7e713504601c237f7d2978768f42
parentc787deb0124b667802d8519bc285894bb6d771d7
Reject tail calls that read from an escaped RESULT_DECL (PR90313)

In this PR we have two return paths from a function "map".  The common
code sets <result> to the value returned by one path, while the other
path does:

   <retval> = map (&<retval>, ...);

We treated this call as tail recursion, losing the copy semantics
on the value returned by the recursive call.

We'd correctly reject the same thing for variables:

   local = map (&local, ...);

The problem is that RESULT_DECLs didn't get the same treatment.

2019-08-09  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
PR middle-end/90313
* tree-tailcall.c (find_tail_calls): Reject calls that might
read from an escaped RESULT_DECL.

gcc/testsuite/
PR middle-end/90313
* g++.dg/torture/pr90313.cc: New test.

From-SVN: r274234
gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/torture/pr90313.cc [new file with mode: 0644]
gcc/tree-tailcall.c