<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 - Dereferencing unsigned __int128 segfaults on Mingw"
   href="https://bugs.llvm.org/show_bug.cgi?id=48941">48941</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Dereferencing unsigned __int128 segfaults on Mingw
          </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>release blocker
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>john@johnmaddock.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This is another showstopper from Boost.Multiprecision, dereferencing an
(unsigned) __int128 segfaults.  Test case is:

#include <assert.h>
#include <type_traits>
#include <cmath>
#include <limits>

template <class T>
struct wraps
{
   T val;
   template <class U>
   wraps(U val, typename
std::enable_if<std::is_floating_point<U>::value>::type* = 0)
   : val(static_cast<T>(std::fabs(val))){}

   wraps(int i) : val(i) {}

   T get()const { return val; }

   const T* limbs()const { return &val; }
   T* limbs() { return &val; }

   template <class R>
   void convert_to(R* result)
   {
      if (*limbs() > (std::numeric_limits<R>::max)())
      {
         if (get() < 0)
         {
            *result = (std::numeric_limits<R>::min)();
         }
         else
         {
            *result = (std::numeric_limits<R>::max)();
         }
      }
      else
      {
         *result = static_cast<R>(*limbs());
      }
   }
};

int main()
{
   float f;
   wraps<unsigned __int128> w(2);
   w.convert_to(&f);

   assert(f == 2);

   return 0;
}

With:

$ clang++ --version
clang version 11.0.0 (<a href="https://github.com/msys2/MINGW-packages">https://github.com/msys2/MINGW-packages</a>
587690290e514a13a7a61be3f9116a1d042d2e4e)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: D:\compilers\msys64\mingw64\bin</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>