<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Coroutine is not accessing the reference correctly in O1"
href="https://bugs.llvm.org/show_bug.cgi?id=47745">47745</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Coroutine is not accessing the reference correctly in O1
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>10.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++2a
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>pushrunkey@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Coroutine a member function of a class that has a reference to a member
variable to access the wrong address in -O1.
<a href="https://godbolt.org/z/aE53rd">https://godbolt.org/z/aE53rd</a>
```
#include <experimental/coroutine>
#include <iostream>
struct Task {
struct promise_type {
auto get_return_object() { return Task{handle_type::from_promise(*this)}; }
std::experimental::suspend_always initial_suspend() { return {}; }
std::experimental::suspend_always final_suspend() noexcept{ return {}; }
void return_void() {}
void unhandled_exception() { }
};
using handle_type = std::experimental::coroutine_handle<promise_type>;
handle_type coro_;
};
struct A{
int&ch;
Task f() {
ch = 42;
// expected &ch == &main.ch
// but &ch == coroutine_handle().address()
std::cout << &ch <<" : "<< ch<<std::endl;
co_return;
}
};
int main(){
int ch=3;
std::cout << &ch <<" : "<< ch<<std::endl;
auto x = A{ch}.f().coro_;
auto y = x;
std::cout<<x.address() <<std::endl;
y.resume();
std::cout << &ch <<" : "<< ch<<std::endl;
}
```
```
$ clang++-10 main.cpp -std=c++2a -stdlib=libc++ -O1 ; ./a.out
0x7fffe85df4ac : 3
0x1369470
0x1369470 : 42
0x7fffe85df4ac : 3
```</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>