[vtk-developers] VTK tickles compiler bug for Altix, gcc 3.3.3

Hank Childs childs3 at llnl.gov
Fri Jul 28 11:07:57 EDT 2006


Hi Folks,

I ran into an issue recently where there appeared to be a bug in the VTK 
library, but I believe was actually a compiler bug.  I don't really have a 
good fix (I believe it is good VTK code).  Regardless, I am reporting it to 
this list in case others encounter it.  

This is for Altix using g++ 3.3.3.

I found that when serializing a data set and writing it to a socket, the 
reader was crashing.  After a lot of digging, I found that the vtkByteSwap 
module was producing garbage the first time it was invoked.  I am speculating 
that there was some sort of hazard.

Searching for an easy fix, I modified vtkByteSwap.cxx's method
   template <class T>
   inline void vtkByteSwapRangeWrite(const T* first, vtkIdType num,
                                     ostream* os, long)
  (located at ~line 130)

  From:

  for(const T* p=first; p != last; ++p)
    {
    T temp = *p;
    vtkByteSwapper<sizeof(T)>::Swap(&temp);
    os->write((char*)&temp, sizeof(temp));
    }


  To:

    for(const T* p=first; p != last; ++p)
    {
    T temp = *p;
    vtkByteSwapper<sizeof(T)>::Swap(&temp);
    T temp2 = *p;
    vtkByteSwapper<sizeof(T)>::Swap(&temp2);
    if (temp != temp2)
        cerr << "A COMPILER BUG HAS BEEN EXPOSED" << endl;
    os->write((char*)&temp, sizeof(temp));
    }

So everyone should be weary when a developer thinks they have found a compiler 
bug.  In this case, I was pretty certain that it was a compiler bug, because 
placing print statements in certain regions of the code caused the byte 
swapper code to work.  The final code is a bit funny ... it calls the same 
method twice (inefficiency, I know) and then checks to make sure that the 
results are the same.  If you call twice and check to see if they are the 
same, it always works (i.e. the print statement won't execute).  If you call 
once (i.e. the original code), it will produce garbage the first time.

-Hank

-- 
____________________________________________________________________________

Hank Childs
VisIt
Lawrence Livermore National Laboratory

phone: (925) 422-4035
email: childs3 at llnl.gov




More information about the vtk-developers mailing list