<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 - std::call_once always segfaults on MinGW (regression 11->12)"
   href="https://bugs.llvm.org/show_bug.cgi?id=50146">50146</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::call_once always segfaults on MinGW (regression 11->12)
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>normal
          </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>blckcat@inbox.ru
          </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>Any use of `std::call_once` on MinGW causes a segfault. It used to work in
Clang 11, but broke in 12.

Minimal example:
    #include <iostream>
    #include <mutex>

    int main()
    {
        std::once_flag flag;
        std::call_once(flag, []{std::cout << "Once!\n";});
    }

The clang version is: Ubuntu clang version
12.0.1-++20210423082613+072c90a863aa-1~exp1~20210423063319.76

The flags I use: clang++-12 --version --target=x86_64-w64-mingw32
--sysroot=/mingw64 -pthread -femulated-tls

The libstdc++ comes from MSYS2 GCC 10.2.0 (rev 10).

Here's what GDB says if I add `-g`:
    Program received signal SIGSEGV, Segmentation fault.
    0x00000001e014dc4a in ?? () from
Z:\home\holyblackcat\Sandbox\2\libgcc_s_seh-1.dll
    (gdb) bt
    #0  0x00000001e014dc4a in ?? () from
Z:\home\holyblackcat\Sandbox\2\libgcc_s_seh-1.dll
    #1  0x00000000004015f3 in std::call_once<main::$_0> (__once=..., __f=...)
at /mingw64/include/c++/10.2.0/mutex:721
    #2  0x00000000004015b5 in main () at 1.cpp:8
    (gdb) f 1
    #1  0x00000000004015f3 in std::call_once<main::$_0> (__once=..., __f=...)
at /mingw64/include/c++/10.2.0/mutex:721
    721           __once_callable = std::__addressof(__callable);
    (gdb) list
    716           auto __callable = [&] {
    717               std::__invoke(std::forward<_Callable>(__f),
    718                             std::forward<_Args>(__args)...);
    719           };
    720     #ifdef _GLIBCXX_HAVE_TLS
    721           __once_callable = std::__addressof(__callable);
    722           __once_call = []{
(*(decltype(__callable)*)__once_callable)(); };
    723     #else
    724           unique_lock<mutex> __functor_lock(__get_once_mutex());
    725           __once_functor = __callable;</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>