Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Dereferencing unsigned __int128 segfaults on Mingw #47910

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR48941
Status NEW
Importance P release blocker
Reported by John Maddock (john@johnmaddock.co.uk)
Reported on 2021-01-29 03:29:13 -0800
Last modified on 2021-01-29 03:59:26 -0800
Version 11.0
Hardware PC Windows NT
CC blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
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
Quuxplusone commented 3 years ago
This is not what I thought it was, it's the comparison that sefaults, reduced
to:

int main()
{
   float f = 0;
   __int128 i = 0;

   return i == f;  // sefault here.
}
Quuxplusone commented 3 years ago
Conversion from __int128 -> float also segfaults:

   float f = 0;
   __int128 i = 2;

   f = i;  //here