<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 - Incorrect behavior with Coroutines TS in opt mode"
href="https://bugs.llvm.org/show_bug.cgi?id=42743">42743</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Incorrect behavior with Coroutines TS in opt mode
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>8.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>priyendra@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>The following program should return an exit code of 0. When compiled in debug
mode, it returns 0 as expected, but returns 200 in opt mode.
Online link: <a href="https://wandbox.org/permlink/gwd2rTDDWcJnE7dS">https://wandbox.org/permlink/gwd2rTDDWcJnE7dS</a>
Godbolt link: <a href="https://godbolt.org/z/wmlbFc">https://godbolt.org/z/wmlbFc</a>
As can be seen from line 68 in the assembly, the generated code is
unconditionally setting EAX to 200 and returning.
Compilation commandline: clang++ prog.cc -Wall -Wextra -O2 -march=native
-std=gnu++2a "-fcoroutines-ts" "-stdlib=libc++"
Have verified that the issue exists in trunk as well.
========================= prog.cc ===============================
#include <experimental/coroutine>
using namespace ::std::experimental;
struct Task {
struct promise_type {
auto initial_suspend() { return suspend_never{}; }
auto final_suspend() { return suspend_never{}; }
auto get_return_object() { return Task{}; }
auto return_void() {}
void unhandled_exception() {}
};
};
struct Awaiter {
coroutine_handle<>* handle;
bool await_ready() { return false; }
void await_suspend(coroutine_handle<> h) { *handle = h; }
void await_resume() {}
};
coroutine_handle<> handleInner, handleOuter;
Task coroInner() { co_await Awaiter{&handleInner}; }
Task coroOuter(bool* done) {
coroInner();
co_await Awaiter{&handleOuter};
*done = true;
}
int main() {
bool done = false;
coroOuter(&done);
if (done) return 100; // error
handleInner.resume();
handleOuter.resume();
if (not done) return 200; // error
return 0; // success
}</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>