<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 - miscompile with templated coroutine"
   href="https://bugs.llvm.org/show_bug.cgi?id=50863">50863</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>miscompile with templated coroutine
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>bhalevy@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following program miscompiles, <a href="https://godbolt.org/z/9nPze58xj">https://godbolt.org/z/9nPze58xj</a>

// Coroutine miscompile reproducer.
//
// clang version 12.0.0
// Target: x86_64-unknown-linux-gnu
//
// Compile with `clang++ -std=c++20 -stdlib=libc++ -fsanitize=undefined -O0`.

#include <experimental/coroutine>

struct task{
  struct promise_type {
    task get_return_object() { return {}; }
    std::experimental::suspend_never initial_suspend() { return {}; }
    std::experimental::suspend_never final_suspend() noexcept { return {}; }
    void return_void() {}
    void unhandled_exception() {}
  };
};

namespace std::experimental {
    template <typename ...Args>
    struct coroutine_traits<task, Args...> {
        using promise_type = typename task::promise_type;
    };
}

template <typename T>
task foo(T) noexcept {
    co_return;
}

int main() {
    foo(0);
}

Compiler output:
ASM generation compiler returned: 0
error: Cannot represent a difference across sections
error: Cannot represent a difference across sections
error: Cannot represent a difference across sections
3 errors generated.
Execution build compiler returned: 1</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>