<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56507>56507</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang 14.0.5 i686-pc-windows-msvc `<coroutine>` ICE: failed to perform tail call elimination on a call site marked musttail
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          StephanTLavavej
      </td>
    </tr>
</table>

<pre>
    Repros with VS 2022 17.3 Preview 3 containing Clang 14.0.5.

:warning: This is specific to **32-bit x86**. :warning:

```
C:\Temp>"C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\Build\vcvars32.bat"
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.3.0-pre.3.0
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'

C:\Temp>type test.cpp
```
```cpp
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <coroutine>
#include <cstdio>
#include <exception>
using namespace std;

int g_tasks_destroyed{0};

struct Task {
    struct Promise {
        int result{-1000};
        coroutine_handle<> previous;

        Task get_return_object() {
            return Task{*this};
        }

        suspend_always initial_suspend() {
            return {};
        }

        auto final_suspend() noexcept {
            struct Awaiter {
                bool await_ready() noexcept {
                    return false;
                }

                void await_resume() noexcept {}

                coroutine_handle<> await_suspend(coroutine_handle<Promise> h) noexcept {
                    auto& pre = h.promise().previous;
                    if (pre) {
                        return pre; // resume awaiting coroutine
                    }

                    // If there is no previous coroutine to resume, we've reached the outermost coroutine.
                    // Return a noop coroutine to allow control to return back to the caller.
                    return noop_coroutine();
                }
            };

            return Awaiter{};
        }

        void return_value(const int v) {
            result = v;
        }

        void unhandled_exception() noexcept {
            terminate();
        }
    };

    using promise_type = Promise;

    bool await_ready() const noexcept {
        return false;
    }

    int await_resume() {
        return coro.promise().result;
    }

    auto await_suspend(coroutine_handle<> enclosing) {
        coro.promise().previous = enclosing;
        return coro; // resume ourselves
    }

    Task(Task&& rhs) noexcept : coro(rhs.coro) {
        rhs.coro = nullptr;
    }

    explicit Task(Promise& p) : coro(coroutine_handle<Promise>::from_promise(p)) {}

    ~Task() {
        ++g_tasks_destroyed;

        if (coro) {
            coro.destroy();
        }
    }

    coroutine_handle<Promise> coro;
};

Task triangular_number(const int n) {
    if (n == 0) {
        co_return 0;
    }

    co_return n + co_await triangular_number(n - 1);
}

int main() {
    assert(g_tasks_destroyed == 0);

    {
        Task t               = triangular_number(10);
        coroutine_handle<> h = t.coro;

        assert(h == t.coro);
        assert(h);
        assert(!h.done());

        h();

        assert(h == t.coro);
        assert(h);
        assert(h.done());

        assert(g_tasks_destroyed == 10); // triangular_number() called for [0, 9]

        const int val = t.coro.promise().result;

        assert(val == 55);
    }

    assert(g_tasks_destroyed == 11); // triangular_number() called for [0, 10]

    puts("Done!");
}
```
```
C:\Temp>cl /EHsc /nologo /W4 /MTd /std:c++20 test.cpp && test.exe
test.cpp
Done!

C:\Temp>clang-cl /EHsc /nologo /W4 /MTd /std:c++20 test.cpp && test.exe
fatal error: error in backend: failed to perform tail call elimination on a call site marked musttail
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\Llvm\\bin\\clang-cl.exe" -cc1 -triple i686-pc-windows-msvc19.33.31627 -emit-obj -mrelax-all -mincremental-linker-compatible --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu pentium4 -mllvm -x86-asm-syntax=intel -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -D_DEBUG -D_MT -flto-visibility-public-std --dependent-lib=libcmtd --dependent-lib=oldnames -stack-protector 2 -fcxx-exceptions -fexceptions -fexternc-nounwind -fms-volatile -fdiagnostics-format msvc -fcoverage-compilation-dir=C:\\Temp -resource-dir "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\Llvm\\lib\\clang\\14.0.5" -c-isystem C:\\MinGW\\include -c-isystem C:\\MinGW\\include\\freetype2 -cxx-isystem C:\\MinGW\\include -cxx-isystem C:\\MinGW\\include\\freetype2 -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\Llvm\\lib\\clang\\14.0.5\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.33.31627\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Auxiliary\\VS\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22000.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22000.0\\\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22000.0\\\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22000.0\\\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22000.0\\\\cppwinrt" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.33.31627\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Auxiliary\\VS\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22000.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22000.0\\\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22000.0\\\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22000.0\\\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22000.0\\\\cppwinrt" -WCL4 -fdeprecated-macro -fdebug-compilation-dir=C:\\Temp -ferror-limit 19 -fmessage-length=120 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.33.31627 -std=c++20 -fdelayed-template-parsing -fno-implicit-modules -fcolor-diagnostics -faddrsig -o C:\\Users\\stl\\AppData\\Local\\Temp\\test-792971.obj -x c++ test.cpp
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'test.cpp'.
4.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@"?triangular_number@@YA?AUTask@@H@Z.resume"'
clang-cl: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 14.0.5
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\Llvm\bin
clang-cl: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-cl: note: diagnostic msg: C:\Users\stl\AppData\Local\Temp\test-67198e.cpp
clang-cl: note: diagnostic msg: C:\Users\stl\AppData\Local\Temp\test-67198e.sh
clang-cl: note: diagnostic msg:

********************
```

This test case was slightly reduced from https://github.com/microsoft/STL/blob/969b2e250df56690768fdf8344293624d6ab0d6c/tests/std/tests/P0912R5_coroutine/test.cpp .

Here's a zip of the original source, preprocessed source, and run script: [repro.zip](https://github.com/llvm/llvm-project/files/9099979/repro.zip)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWllz2zgS_jXyCwoqirIk68EPsmQnrnU2rthJZvfFBZGghAmvAkBZnl-_X4OkqIOylZnJTmpqVDYPHN2NvtDdxDwLXy4_yVxnhj0ru2RfHpjv-T7rjbp9dq_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