[llvm-bugs] [Bug 48941] New: Dereferencing unsigned __int128 segfaults on Mingw

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 29 03:29:13 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=48941

            Bug ID: 48941
           Summary: Dereferencing unsigned __int128 segfaults on Mingw
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: john at johnmaddock.co.uk
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210129/fa149442/attachment-0001.html>


More information about the llvm-bugs mailing list