<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 - Regression in coroutines between clang 10 and clang 11 with compiler crash in -O2 -g ("broken function")"
   href="https://bugs.llvm.org/show_bug.cgi?id=46784">46784</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Regression in coroutines between clang 10 and clang 11 with compiler crash in -O2 -g ("broken function")
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>C++2a
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>bartde@microsoft.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, gornishanov@gmail.com, hans@chromium.org, JunMa@linux.alibaba.com, llvm-bugs@lists.llvm.org, modocache@gmail.com, richard-llvm@metafoo.co.uk
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>46725
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This is blocking us to move to clang 11 and get fixes for various
coroutine-related bugs.



Error:

mismatched subprogram between llvm.dbg.value variable and !dbg attachment

  call void @llvm.dbg.value(metadata %"class.std::__1::vector"* undef, metadata
!5008, metadata !DIExpression()), !dbg !5213

label %133

void (%"_ZZ17clang11_bug_reprovENK3$_0clEv.Frame"*)*
@"_ZZ17clang11_bug_reprovENK3$_0clEv.resume"

!5008 = !DILocalVariable(name: "awaitables", arg: 1, scope: !5004, file: !69,
line: 58, type: !4638)

!5004 = distinct !DISubprogram(name: "my_operator<my_void_task>", linkageName:
"_Z11my_operatorI12my_void_taskEDaONSt3__16vectorIT_NS1_9allocatorIS3_EEEE",
scope: !69, file: !69, line: 58, type: !5005, scopeLine: 59, flags:
DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition |
DISPFlagOptimized, unit: !0, templateParams: !5009, retainedNodes: !5007)

!5213 = !DILocation(line: 0, scope: !1513, inlinedAt: !5212)

!1513 = distinct !DISubprogram(name: "my_operator<my_void_task>", linkageName:
"_Z11my_operatorI12my_void_taskEDaONSt3__16vectorIT_NS1_9allocatorIS3_EEEE",
scope: !69, file: !69, line: 58, type: !1514, scopeLine: 59, flags:
DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition |
DISPFlagOptimized, unit: !0, templateParams: !1518, retainedNodes: !1516)

fatal error: error in backend: Broken function

PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace, preprocessed source, and associated run script.

Stack dump:

0.      Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang++ -g -o
./output.s -mllvm --x86-asm-syntax=intel -S
--gcc-toolchain=/opt/compiler-explorer/gcc-9.2.0 -fcolor-diagnostics
-fno-crash-diagnostics -std=c++2a -O2 -g -fcoroutines-ts -stdlib=libc++
<source> 

1.      <eof> parser at end of file

2.      Per-module optimization passes

3.      Running pass 'CallGraph Pass Manager' on module '<source>'.

4.      While splitting coroutine @"_ZZ17clang11_bug_reprovENK3$_0clEv"

 #0 0x000055633a45075a llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2cad75a)

 #1 0x000055633a44e504 llvm::sys::RunSignalHandlers()
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2cab504)

 #2 0x000055633a44e775 llvm::sys::CleanupOnSignal(unsigned long)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2cab775)

 #3 0x000055633a3c3882 llvm::CrashRecoveryContext::HandleExit(int)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2c20882)

 #4 0x000055633a4473d7 llvm::sys::Process::Exit(int)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2ca43d7)

 #5 0x00005563386289b1 LLVMErrorHandler(void*, std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&, bool)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0xe859b1)

 #6 0x000055633a3ca029 llvm::report_fatal_error(llvm::Twine const&, bool)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2c27029)

 #7 0x000055633a3ca168
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2c27168)

 #8 0x000055633b5a875e postSplitCleanup(llvm::Function&)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e0575e)

 #9 0x000055633b5a93f1 splitSwitchCoroutine(llvm::Function&,
llvm::coro::Shape&, llvm::SmallVectorImpl<llvm::Function*>&)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e063f1)

#10 0x000055633b5aaf70 splitCoroutine(llvm::Function&,
llvm::SmallVectorImpl<llvm::Function*>&) (.constprop.449)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e07f70)

#11 0x000055633b5ac614 (anonymous
namespace)::CoroSplitLegacy::runOnSCC(llvm::CallGraphSCC&) (.part.448)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e09614)

#12 0x0000556339683bbf (anonymous
namespace)::CGPassManager::runOnModule(llvm::Module&)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x1ee0bbf)

#13 0x0000556339d832c1 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x25e02c1)

#14 0x000055633a6d181d (anonymous
namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2f2e81d)

#15 0x000055633a6d344b clang::EmitBackendOutput(clang::DiagnosticsEngine&,
clang::HeaderSearchOptions const&, clang::CodeGenOptions const&,
clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout
const&, llvm::Module*, clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2f3044b)

#16 0x000055633b2161f4
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a731f4)

#17 0x000055633bf872b9 clang::ParseAST(clang::Sema&, bool, bool)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x47e42b9)

#18 0x000055633ac3cb89 clang::FrontendAction::Execute()
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x3499b89)

#19 0x000055633abf694b
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x345394b)

#20 0x000055633ad02f7b
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x355ff7b)

#21 0x0000556338629f3c cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xe86f3c)

#22 0x0000556338626a3d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0xe83a3d)

#23 0x000055633aacf3f5 void llvm::function_ref<void
()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::__cxx11::basic_string<char, std::char_traits<char>,</span >
std::allocator<char> >*, bool*) const::'lambda'()>(long)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x332c3f5)

#24 0x000055633a3c3713
llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2c20713)

#25 0x000055633aacfed0
clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::__cxx11::basic_string<char, std::char_traits<char>,</span >
std::allocator<char> >*, bool*) const (.part.148)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x332ced0)

#26 0x000055633aaaa0a5
clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&,
clang::driver::Command const*&) const
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x33070a5)

#27 0x000055633aaaaaef
clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x3307aef)

#28 0x000055633aab3685
clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x3310685)

#29 0x0000556338566921 main
(/opt/compiler-explorer/clang-trunk/bin/clang+++0xdc3921)

#30 0x00007ff5f84fdb97 __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x21b97)

#31 0x00005563386265ba _start
(/opt/compiler-explorer/clang-trunk/bin/clang+++0xe835ba)

clang-12: error: clang frontend command failed with exit code 70 (use -v to see
invocation)

ASM generation compiler returned: 70

mismatched subprogram between llvm.dbg.value variable and !dbg attachment

  call void @llvm.dbg.value(metadata %"class.std::__1::vector"* undef, metadata
!5008, metadata !DIExpression()), !dbg !5213

label %133

void (%"_ZZ17clang11_bug_reprovENK3$_0clEv.Frame"*)*
@"_ZZ17clang11_bug_reprovENK3$_0clEv.resume"

!5008 = !DILocalVariable(name: "awaitables", arg: 1, scope: !5004, file: !69,
line: 58, type: !4638)

!5004 = distinct !DISubprogram(name: "my_operator<my_void_task>", linkageName:
"_Z11my_operatorI12my_void_taskEDaONSt3__16vectorIT_NS1_9allocatorIS3_EEEE",
scope: !69, file: !69, line: 58, type: !5005, scopeLine: 59, flags:
DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition |
DISPFlagOptimized, unit: !0, templateParams: !5009, retainedNodes: !5007)

!5213 = !DILocation(line: 0, scope: !1513, inlinedAt: !5212)

!1513 = distinct !DISubprogram(name: "my_operator<my_void_task>", linkageName:
"_Z11my_operatorI12my_void_taskEDaONSt3__16vectorIT_NS1_9allocatorIS3_EEEE",
scope: !69, file: !69, line: 58, type: !1514, scopeLine: 59, flags:
DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition |
DISPFlagOptimized, unit: !0, templateParams: !1518, retainedNodes: !1516)

fatal error: error in backend: Broken function

clang-12: error: clang frontend command failed with exit code 70 (use -v to see
invocation)

Execution build compiler returned: 70



Compiler flags:

-std=c++2a -O2 -g -fcoroutines-ts -stdlib=libc++



Minimal repro (<a href="https://godbolt.org/z/91Ers9">https://godbolt.org/z/91Ers9</a>):

#define REPRO_NEED_VECTOR_ELEM 1
#define REPRO_NEED_MOVE 1

#include <experimental/coroutine>

struct my_void_task final
{
    struct promise_type final
    {
        my_void_task get_return_object() noexcept { return my_void_task{this};
}

        void return_void() const noexcept {}
        void unhandled_exception() const {}

        std::experimental::suspend_always initial_suspend() const noexcept {
return {}; }
        std::experimental::suspend_always final_suspend() const noexcept {
return {}; }
    };

    using coroutine_handle_promise_t =
std::experimental::coroutine_handle<promise_type>;

    my_void_task() = delete;

    my_void_task(const my_void_task&) = delete;
    my_void_task& operator=(const my_void_task&) = delete;

    my_void_task(my_void_task && task) noexcept
        : m_coro{task.m_coro}
    {
        task.m_coro = nullptr;
    }

    my_void_task& operator=(my_void_task&& task) noexcept
    {
        return *this; // NB: Removed all code
    }

  private:
    explicit my_void_task(promise_type * p)
        : m_coro{coroutine_handle_promise_t::from_promise(*p)}
    {
    }

    coroutine_handle_promise_t m_coro;
};

#include <vector>

template <typename Awaitable>
auto my_operator(std::vector<Awaitable>&& awaitables)
{
    struct awaitable final
    {
        awaitable(std::vector<Awaitable> awaitables)
            : m_awaitables{std::move(awaitables)}
        {
        }

        struct awaiter final
        {
            bool await_ready() { return false; }
            void await_suspend(std::experimental::coroutine_handle<>) {}
            int await_resume() { return 42; }
        };

        awaiter operator co_await() { return {}; }

      private:
        std::vector<Awaitable> m_awaitables;
    };

    return awaitable{std::move(awaitables)};
}


my_void_task hhh()
{
    co_return;
}

void clang11_bug_repro()
{
    auto f = []() -> my_void_task {
        std::vector<my_void_task> v{};

#if REPRO_NEED_VECTOR_ELEM
        v.push_back(hhh());
#endif

#if REPRO_NEED_MOVE
        auto w = my_operator(std::move(v));

        auto x = co_await std::move(w);
#else
        auto x = co_await when_any(std::move(v));
#endif
    };

    auto g = f();
}</pre>
        </div>
      </p>

        <div id="referenced">
          <hr style="border: 1px dashed #969696">
          <b>Referenced Bugs:</b>
          <ul>
              <li>
                [<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [meta] 11.0.0 Release Blockers"
   href="https://bugs.llvm.org/show_bug.cgi?id=46725">Bug 46725</a>] [meta] 11.0.0 Release Blockers
              </li>
          </ul>
        </div>
        <br>

      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>