[llvm-bugs] [Bug 42743] New: Incorrect behavior with Coroutines TS in opt mode

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jul 24 10:20:32 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42743

            Bug ID: 42743
           Summary: Incorrect behavior with Coroutines TS in opt mode
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: priyendra at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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: https://wandbox.org/permlink/gwd2rTDDWcJnE7dS
Godbolt link: https://godbolt.org/z/wmlbFc

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
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190724/5582d856/attachment-0001.html>


More information about the llvm-bugs mailing list