[vtk-developers] Help with 2 warnings in TestFastNumericConversion.cxx and vtkDistributedGraphHelper.cxx

Sean McBride sean at rogue-research.com
Wed Apr 3 15:47:03 EDT 2013


Hi all,

I've been working on enabling more clang warnings on my dashboard... And need help with:

1)
Common/Math/Testing/Cxx/TestFastNumericConversion.cxx:55:18: warning: dereference of type 'int *' that was reinterpret_cast from type 'double *' has undefined behavior [-Wundefined-reinterpret-cast]
      ival[i] = *reinterpret_cast<int *>(&dval[i]);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is indeed wonky.  As 'double' is usually 64 bit and 'int' is usually 32, this is reinterpreting only half the bits of the double (which half depending on CPU endianness).  It does this in a big loop, times it, and uses that as a baseline time later compared to other techniques.  The test's entire foundation is suspect... what to do?

2)
Common/DataModel/vtkDistributedGraphHelper.cxx:191:49: warning: signed shift result (0x80000000) sets the sign bit of the shift expression's type
      ('vtkIdType' (aka 'int')) and becomes negative [-Wshift-sign-overflow]
  this->signBitMask = static_cast<vtkIdType>(1) << ((sizeof(vtkIdType) * CHAR_BIT) - 1);
                      ~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Shifting a 1 bit into or past the sign bit is undefined behaviour.  If I'm not mistaken, we can just use VTK_ID_MIN here, right?

Thanks,

-- 
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada





More information about the vtk-developers mailing list