So compiling this testcase with -fsantize=address we get an use
after the lifetime is gone. In this case it is the rvalue reference
argument to my_coro. With more inlining into main, this testcase
started to fail at -O3 as we remove the store to the temporary now
as the access is after the lifetime of the temporary has ended.
The best way of fixing this is creating an rvalue reference that will
then forward into the argument. This means we have the rvalue reference
no longer as a temporary that ends at the end of the statement but rather
end of the scope (since it is extended).
Tested on x86_64-linux-gnu with the testcase now passing at -O3.
PR testsuite/124548
gcc/testsuite/ChangeLog:
* g++.dg/coroutines/torture/func-params-07.C (main): Fix lifetime
issue of rvalue reference.
Signed-off-by: Andrew Pinski <[email protected]>
---
gcc/testsuite/g++.dg/coroutines/torture/func-params-07.C | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gcc/testsuite/g++.dg/coroutines/torture/func-params-07.C
b/gcc/testsuite/g++.dg/coroutines/torture/func-params-07.C
index 03044ef4b31..37ff08d73f5 100644
--- a/gcc/testsuite/g++.dg/coroutines/torture/func-params-07.C
+++ b/gcc/testsuite/g++.dg/coroutines/torture/func-params-07.C
@@ -21,7 +21,8 @@ int main ()
PRINT ("main: create coro1");
int lv = 1;
int lvr = 2;
- coro1 x = my_coro (lv, lvr, lvr+2);
+ int &&rvr = lvr+2;
+ coro1 x = my_coro (lv, lvr, std::forward<int>(rvr));
if (x.handle.done())
abort();
--
2.43.0