[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

ITK 4.1 patches for gcc 4.7



Ok, I have just built ITK 4.1 successfully with gcc 4.7 on amd64. All my
patches are attached here (just to have them in one place). 

Fix-gcc4.7-FEM-Tests.patch: this was posted before, and there is a
similar fix already in upstream. Don't know if you want to use this one
or grab upstream's version.

SpatialObject-Test-Segfaults.patch: Fixes the segfaults, in the spatial
object tests.

narrowing-conversion-warnings.patch: Just gets rid of a couple compiler
warnings. Basically unsigned and signed conversion stuff.

There is still one more warning, coming from itkFixedArray.h, maybe I'll
get to that later.

Hopefully these fix some of the errors on the other architectures,
although I think i386 has more failures.

-Paul
Description: Fix Failed FEM Tests on gcc 4.7
 With any optimization (-O1, -O2, -O3), the following tests were failing
 .
        557 - itkFEMC0HexahedralElement-NodalLoads-BCs (Failed)
        559 - itkFEMC0HexahedralElement-GravityLoad-BCs (Failed)
        560 - itkFEMC0TetrahedralElement-NodalLoads-BCs (Failed)
        562 - itkFEMC0TetrahedralElement-GravityLoad-BCs (Failed)
        563 - itkFEMC0QuadElement-NodalLoads-BCs (Failed)
        564 - itkFEMC0QuadElement-Strain (Failed)
        566 - itkFEMC0QuadElement-GravityLoad-BCs (Failed)
        567 - itkFEMLoadLandmarkImplementation (Failed)
        569 - itkFEMC0TriangularElement-NodalLoads-BCs (Failed)
        572 - itkFEMC0TriangularElement-Quadratic (Failed)
        573 - itkFEMTruss (Failed) 
 .
 It looks like expectedSolution in the code below was pointing to some
 unitialized memory. So while the tests were giving the right result, the
 expectedSolution was wrong. This change just sets expectedSolution
 directly instead of pointing it to the first element in an array that is 
 no longer on the stack.
Author: Paul Novotny <paul@paulnovo.us>

--- debian-svn.orig/Modules/Numerics/FEM/test/itkFEMElement2DTest.cxx
+++ debian-svn/Modules/Numerics/FEM/test/itkFEMElement2DTest.cxx
@@ -90,7 +90,8 @@
 
   femSO->GetFEMObject()->FinalizeMesh();
 
-  double *    expectedSolution = NULL;
+  double      expectedSolution[12];
+  bool        haveExpectedSolution = false;
   bool        foundError = false;
   std::string modelFile = itksys::SystemTools::GetFilenameName( argv[1] );
 
@@ -137,135 +138,103 @@
       if( modelFile == "quad2-small.meta" )
         {
         tolerance = 10e-10;
-        double quad2smallExpectedSolution[8] =
-          {
-          0, 0,
-          2.97334e-07, -1.20555e-06,
-          1.944e-06, -1.32333e-06,
-          0, 0
-          };
-        expectedSolution = &(quad2smallExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = 2.97334e-07;  expectedSolution[3] = -1.20555e-06;
+        expectedSolution[4] = 1.944e-06;    expectedSolution[5] = -1.32333e-06;
+        expectedSolution[6] = 0;            expectedSolution[7] = 0;
         }
       else if( modelFile == "quad2-strain.meta" )
         {
         tolerance = 10e-10;
-        double quad2strainExpectedSolution[8] =
-          {
-          0, 0,
-          2.56204e-07, -1.02482e-06,
-          1.67956e-06, -1.19562e-06,
-          0, 0
-          };
-        expectedSolution = &(quad2strainExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = 2.56204e-07;  expectedSolution[3] = -1.02482e-06;
+        expectedSolution[4] = 1.67956e-06;  expectedSolution[5] = -1.19562e-06;
+        expectedSolution[6] = 0;            expectedSolution[7] = 0;
         }
       else if( modelFile == "quad4.meta" )
         {
         tolerance = 10e-10;
-        double quad4ExpectedSolution[8] =
-          {
-          0, 0,
-          0, 0,
-          0, 0,
-          0, 0
-          };
-        expectedSolution = &(quad4ExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = 0;            expectedSolution[3] = 0;
+        expectedSolution[4] = 0;            expectedSolution[5] = 0;
+        expectedSolution[6] = 0;            expectedSolution[7] = 0;
         }
       else if( modelFile == "quad6-grav.meta" )
         {
         tolerance = 10e-10;
-        double quad6gravExpectedSolution[8] =
-          {
-          0, 0,
-          0, 0,
-          -5.32164e-08, 1.59649e-07,
-          5.32164e-08, 1.59649e-07
-          };
-        expectedSolution = &(quad6gravExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = 0;            expectedSolution[3] = 0;
+        expectedSolution[4] = -5.32164e-08; expectedSolution[5] = 1.59649e-07;
+        expectedSolution[6] = 5.32164e-08;  expectedSolution[7] = 1.59649e-07;
         }
       else if( modelFile == "quad-lm.meta" )
         {
         tolerance = 10e-7;
-        double quadlmExpectedSolution[8] =
-          {
-          0, 0,
-          -8.76093e-05, -0.0135944,
-          -0.00420457, 0.00477804,
-          -0.0163679, -0.0360446,
-          };
-        expectedSolution = &(quadlmExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = -8.76093e-05; expectedSolution[3] = -0.0135944;
+        expectedSolution[4] = -0.00420457;  expectedSolution[5] = 0.00477804;
+        expectedSolution[6] = -0.0163679;   expectedSolution[7] = -0.0360446;
         }
       else if( modelFile == "trapezoid.meta" )
         {
         tolerance = 10e-10;
-        double trapezoidExpectedSolution[8] =
-          {
-          0, 0,
-          0, 0,
-          0, 0,
-          0, 0
-          };
-        expectedSolution = &(trapezoidExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = 0;            expectedSolution[3] = 0;
+        expectedSolution[4] = 0;            expectedSolution[5] = 0;
+        expectedSolution[6] = 0;            expectedSolution[7] = 0;
         }
       else if( modelFile == "tri2.meta" )
         {
         tolerance = 10e-6;
-        double tri2ExpectedSolution[8] =
-          {
-          0, 0,
-          9.86667e-07, -2.028e-05,
-          -9.76e-06, -5.67867e-05,
-          -2.87733e-05, -9.68267e-05
-          };
-        expectedSolution = &(tri2ExpectedSolution[0]);
-
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = 9.86667e-07;  expectedSolution[3] = -2.028e-05;
+        expectedSolution[4] = -9.76e-06;    expectedSolution[5] = -5.67867e-05;
+        expectedSolution[6] = -2.87733e-05; expectedSolution[7] = -9.68267e-05;
         }
       else if( modelFile == "tri3.meta" )
         {
         tolerance = 10e-10;
-        double tri3ExpectedSolution[6] =
-          {
-          0, 0,
-          0, 0,
-          0, 0
-          };
-        expectedSolution = &(tri3ExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = 0;            expectedSolution[3] = 0;
+        expectedSolution[4] = 0;            expectedSolution[5] = 0;
         }
       else if( modelFile == "tri3-e.meta" )
         {
         tolerance = 10e-10;
-        double tri3eExpectedSolution[6] =
-          {
-          0, 0,
-          0, 0,
-          0, 0
-          };
-        expectedSolution = &(tri3eExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = 0;            expectedSolution[3] = 0;
+        expectedSolution[4] = 0;            expectedSolution[5] = 0;
         }
       else if( modelFile == "tri3-q.meta" )
         {
         tolerance = 10e-9;
-        double tri3qExpectedSolution[12] =
-          {
-          0, 0,
-          -3.315e-07, 1.57527e-06,
-          4.98323e-06, 7.36775e-07,
-          -5.3625e-08, 2.18676e-06,
-          8.32488e-07, 1.04065e-06,
-          5.22113e-07, 2.42889e-06
-          };
-        expectedSolution = &(tri3qExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = -3.315e-07;   expectedSolution[3] = 1.57527e-06;
+        expectedSolution[4] = 4.98323e-06;  expectedSolution[5] = 7.36775e-07;
+        expectedSolution[6] = -5.3625e-08;  expectedSolution[7] = 2.18676e-06;
+        expectedSolution[8] = 8.32488e-07;  expectedSolution[9] = 1.04065e-06;
+        expectedSolution[10] = 5.22113e-07; expectedSolution[11] = 2.42889e-06;
         }
       else if( modelFile == "truss.meta" )
         {
         tolerance = 10e-7;
-        double trussExpectedSolution[11] =
-          {
-          0, 0, -0.179399,
-          0.00169764, -0.478397, 0,
-          0.00339527, 0, 0.179399,
-          0.392323, -0.505307
-          };
-        expectedSolution = &(trussExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = -0.179399;    expectedSolution[3] = 0.00169764;
+        expectedSolution[4] = -0.478397;    expectedSolution[5] = 0;
+        expectedSolution[6] = 0.00339527;   expectedSolution[7] = 0;
+        expectedSolution[8] =  0.179399;    expectedSolution[9] = 0.392323;
+        expectedSolution[10] = -0.505307;
         }
       else
         {
@@ -293,7 +262,7 @@
         }
       else
         {
-        if( expectedSolution != NULL )
+        if( haveExpectedSolution )
           {
           bool testError = CheckDisplacements1(solver, s, expectedSolution, tolerance);
           if( testError )
--- debian-svn.orig/Modules/Numerics/FEM/test/itkFEMElement3DTest.cxx
+++ debian-svn/Modules/Numerics/FEM/test/itkFEMElement3DTest.cxx
@@ -92,7 +92,8 @@
 
   femSO->GetFEMObject()->FinalizeMesh();
 
-  double *    expectedSolution = NULL;
+  double      expectedSolution[24];
+  bool        haveExpectedSolution = false;
   bool        foundError = false;
   std::string modelFile = itksys::SystemTools::GetFilenameName( argv[1] );
 
@@ -139,87 +140,88 @@
       if( modelFile == "hexa2.meta" )
         {
         tolerance = 10e-6;
-        double hex2expectedSolution[24] =
-          {
-          -0.086324, -0.00055514, 0.121079,
-          0.0952793, -0.00331153, 0.114235,
-          0.0727445, 0.00768949, -0.0394109,
-          -0.0774779, -0.0115562, -0.0325665,
-          0, 0, 0.0713128,
-          0, 0, 0.0734239,
-          0.0439568, 0, 0.00211102,
-          -0.0397348, 0, 0
-          };
-        expectedSolution = &(hex2expectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = -0.086324;    expectedSolution[1] = -0.00055514;
+        expectedSolution[2] = 0.121079;     expectedSolution[3] = 0.0952793;
+        expectedSolution[4] = -0.00331153;  expectedSolution[5] = 0.114235;
+        expectedSolution[6] = 0.0727445;    expectedSolution[7] = 0.00768949;
+        expectedSolution[8] = -0.0394109;   expectedSolution[9] = -0.0774779;
+        expectedSolution[10] = -0.0115562;  expectedSolution[11] = -0.0325665;
+        expectedSolution[12] = 0;           expectedSolution[13] = 0;
+        expectedSolution[14] = 0.0713128;   expectedSolution[15] = 0;
+        expectedSolution[16] = 0;           expectedSolution[17] = 0.0734239;
+        expectedSolution[18] = 0.0439568;   expectedSolution[19] = 0;
+        expectedSolution[20] = 0.00211102;  expectedSolution[21] = -0.0397348;
+        expectedSolution[22] = 0;           expectedSolution[23] = 0;
         }
       else if( modelFile == "hexa3.meta" )
         {
         tolerance = 10e-10;
-        double hex3ExpectedSolution[24] =
-          {
-          0, 0, 0,
-          0, 0, 0,
-          0, 0, 0,
-          0, 0, 0,
-          0, 0, 0,
-          0, 0, 0,
-          0, 0, 0,
-          0, 0, 0
-          };
-        expectedSolution = &(hex3ExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = 0;            expectedSolution[3] = 0;
+        expectedSolution[4] = 0;            expectedSolution[5] = 0;
+        expectedSolution[6] = 0;            expectedSolution[7] = 0;
+        expectedSolution[8] = 0;            expectedSolution[9] = 0;
+        expectedSolution[10] = 0;           expectedSolution[11] = 0;
+        expectedSolution[12] = 0;           expectedSolution[13] = 0;
+        expectedSolution[14] = 0;           expectedSolution[15] = 0;
+        expectedSolution[16] = 0;           expectedSolution[17] = 0;
+        expectedSolution[18] = 0;           expectedSolution[19] = 0;
+        expectedSolution[20] = 0;           expectedSolution[21] = 0;
+        expectedSolution[22] = 0;           expectedSolution[23] = 0;
         }
       else if( modelFile == "hexa4-grav.meta" )
         {
         tolerance = 10e-10;
-        double hex4GravExpectedSolution[24] =
-          {
-          0, 0, 0,
-          0, 0, 0,
-          0, 0, 0,
-          9.27489e-08, 2.95922e-06, -9.27489e-08,
-          -1.49661e-06, 8.59118e-07, 1.38971e-06,
-          -1.32956e-06, -5.70152e-07, 1.32956e-06,
-          -1.38971e-06, 8.59118e-07, 1.49661e-06,
-          -1.59154e-06, 2.37079e-06, 1.59154e-06
-          };
-        expectedSolution = &(hex4GravExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;             expectedSolution[1] = 0;
+        expectedSolution[2] = 0;             expectedSolution[3] = 0;
+        expectedSolution[4] = 0;             expectedSolution[5] = 0;
+        expectedSolution[6] = 0;             expectedSolution[7] = 0;
+        expectedSolution[8] = 0;             expectedSolution[9] = 9.27489e-08;
+        expectedSolution[10] = 2.95922e-06;  expectedSolution[11] = -9.27489e-08;
+        expectedSolution[12] = -1.49661e-06; expectedSolution[13] = 8.59118e-07;
+        expectedSolution[14] = 1.38971e-06;  expectedSolution[15] = -1.32956e-06;
+        expectedSolution[16] = -5.70152e-07; expectedSolution[17] = 1.32956e-06;
+        expectedSolution[18] = -1.38971e-06; expectedSolution[19] = 8.59118e-07;
+        expectedSolution[20] = 1.49661e-06;  expectedSolution[21] = -1.59154e-06;
+        expectedSolution[22] = 2.37079e-06;  expectedSolution[23] = 1.59154e-06;
         }
       else if( modelFile == "tetra2.meta" )
         {
         tolerance = 10e-9;
-        double tetra2ExpectedSolution[15] =
-          {
-          0, 0, 0,
-          0, 0, -0.000866667,
-          0, 0, -0.000866667,
-          0, 0, 0,
-          0, 0, 0
-          };
-        expectedSolution = &(tetra2ExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = 0;            expectedSolution[3] = 0;
+        expectedSolution[4] = 0;            expectedSolution[5] = -0.000866667;
+        expectedSolution[6] = 0;            expectedSolution[7] = 0;
+        expectedSolution[8] = -0.000866667; expectedSolution[9] = 0;
+        expectedSolution[10] = 0;           expectedSolution[11] = 0;
+        expectedSolution[12] = 0;           expectedSolution[13] = 0;
+        expectedSolution[14] = 0;
         }
       else if( modelFile == "tetra3.meta" )
         {
         tolerance = 10e-10;
-        double tetra3ExpectedSolution[12] =
-          {
-          0, 0, 0,
-          0, 0, 0,
-          0, 0, 0,
-          0, 0, 0
-          };
-        expectedSolution = &(tetra3ExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = 0;            expectedSolution[3] = 0;
+        expectedSolution[4] = 0;            expectedSolution[5] = 0;
+        expectedSolution[6] = 0;            expectedSolution[7] = 0;
+        expectedSolution[8] = 0;            expectedSolution[9] = 0;
+        expectedSolution[10] = 0;           expectedSolution[11] = 0;
         }
       else if( modelFile == "tetra4-grav.meta" )
         {
         tolerance = 10e-9;
-        double tetra4gravExpectedSolution[12] =
-          {
-          0, 0, 0,
-          0, 0, 0,
-          0, 0, 0,
-          0, 0, 1.46858e-05
-          };
-        expectedSolution = &(tetra4gravExpectedSolution[0]);
+        haveExpectedSolution = true;
+        expectedSolution[0] = 0;            expectedSolution[1] = 0;
+        expectedSolution[2] = 0;            expectedSolution[3] = 0;
+        expectedSolution[4] = 0;            expectedSolution[5] = 0;
+        expectedSolution[6] = 0;            expectedSolution[7] = 0;
+        expectedSolution[8] = 0;            expectedSolution[9] = 0;
+        expectedSolution[10] = 0;           expectedSolution[11] = 1.46858e-05;
         }
       else
         {
@@ -231,7 +233,7 @@
       PrintNodalCoordinates1(solver, s);
       // PrintU(S, s, );
 
-      if( expectedSolution != NULL )
+      if( haveExpectedSolution )
         {
         bool testError = CheckDisplacements1(solver, s, expectedSolution, tolerance);
         if( testError )
Description: Fix narrowing warning compiler messages
 Just fixed up some minor compiler warnings that come about when using
 -Wall. These are all variable narrowing, basically conversions between
 signed and unsigned variables.
Author: Paul Novotny <paul@paulnovo.us>

--- debian-svn.orig/Modules/Compatibility/Deprecated/test/itk2DDeformableTest.cxx
+++ debian-svn/Modules/Compatibility/Deprecated/test/itk2DDeformableTest.cxx
@@ -29,8 +29,8 @@
 int itk2DDeformableTest(int, char* [])
 {
 // change the image size to your test images
-  int WIDTH = 100;
-  int HEIGHT = 100;
+  unsigned long WIDTH = 100;
+  unsigned long HEIGHT = 100;
 
   // Define the dimension of the images
   const unsigned int myDimension = 2;
--- debian-svn.orig/Modules/Compatibility/Deprecated/test/itkDeformableTest.cxx
+++ debian-svn/Modules/Compatibility/Deprecated/test/itkDeformableTest.cxx
@@ -28,9 +28,9 @@
 
 int itkDeformableTest(int , char *[])
 {
-  int WIDTH = 32;
-  int HEIGHT = 32;
-  int DEPTH = 32;
+  unsigned long WIDTH = 32;
+  unsigned long HEIGHT = 32;
+  unsigned long DEPTH = 32;
 
   // Define the dimension of the images
   const unsigned int myDimension = 3;
--- debian-svn.orig/Modules/Filtering/ImageStatistics/test/itkImagePCAShapeModelEstimatorTest.cxx
+++ debian-svn/Modules/Filtering/ImageStatistics/test/itkImagePCAShapeModelEstimatorTest.cxx
@@ -39,8 +39,8 @@
 int itkImagePCAShapeModelEstimatorTest(int, char* [] )
 {
   //Data definitions
-  int IMGWIDTH          = 2;
-  int IMGHEIGHT         = 2;
+  unsigned long IMGWIDTH = 2;
+  unsigned long IMGHEIGHT = 2;
   const int NDIMENSION  = 2;
   unsigned int NUMTRAINIMAGES = 3;
   unsigned int NUMLARGESTPC = 2;
--- debian-svn.orig/Modules/Filtering/ImageGrid/test/itkWarpImageFilterTest2.cxx
+++ debian-svn/Modules/Filtering/ImageGrid/test/itkWarpImageFilterTest2.cxx
@@ -70,7 +70,7 @@
   return image;
 }
 
-DisplacementFieldType::Pointer MakeDisplacementField(int dim)
+DisplacementFieldType::Pointer MakeDisplacementField(long unsigned int dim)
 {
   typedef itk::ImageRegionIterator<DisplacementFieldType> IteratorType;
   DisplacementFieldType::SizeType size = {{dim,dim,dim}};
--- debian-svn.orig/Modules/Core/SpatialObjects/test/itkImageMaskSpatialObjectTest2.cxx
+++ debian-svn/Modules/Core/SpatialObjects/test/itkImageMaskSpatialObjectTest2.cxx
@@ -144,14 +144,16 @@
 
   // Check if insideregion is properly computed at the image boundary
   {
+  typedef typename ImageType::IndexType::OffsetType OffsetType;
+  typedef typename OffsetType::OffsetValueType OffsetValueType;
   ImageType::IndexType startPointIndex =
     {{ insideIndex[0]-2,
        insideIndex[1]-2,
        insideIndex[2]-2 }};
   ImageType::IndexType endPointIndex =
-    {{ insideIndex[0]+insideSize[0]+2,
-       insideIndex[1]+insideSize[1]+2,
-       insideIndex[2]+insideSize[2]+2 }};
+    {{ insideIndex[0] + static_cast< OffsetValueType >(insideSize[0])+2,
+       insideIndex[1] + static_cast< OffsetValueType >(insideSize[1])+2,
+       insideIndex[2] + static_cast< OffsetValueType >(insideSize[2])+2 }};
   ImageType::PointType startPoint;
   ImageType::PointType endPoint;
   image->TransformIndexToPhysicalPoint( startPointIndex, startPoint );
Description: Fix Spatial Object Test Segfaults
 This bug fixes some segfaults that occur when compiling with O3 on gcc
 4.7. I am not 100% sure why this works. ComputeMatrix looks fine, just 
 that it is a bit unusual to use the final counter value of the for loop
 as a condition in the next if. I am thinking gcc does some for-loop
 branching optimization that does't like this. 
Author: Paul Novotny <paul@paulnovo.us>

--- debian-svn.orig/Modules/Core/Transform/include/itkScalableAffineTransform.hxx
+++ debian-svn/Modules/Core/Transform/include/itkScalableAffineTransform.hxx
@@ -180,20 +180,19 @@
 ScalableAffineTransform< TScalarType, NDimensions >
 ::ComputeMatrix()
 {
-  unsigned int i;
-
-  for ( i = 0; i < NDimensions; i++ )
+  bool scaleChanged = false;
+  for ( unsigned int i = 0; i < NDimensions; i++ )
     {
     if ( m_Scale[i] != m_MatrixScale[i] )
       {
-      break;
+      scaleChanged = true;
       }
     }
-  if ( i < NDimensions )
+  if ( scaleChanged )
     {
     MatrixType mat;
     typename MatrixType::InternalMatrixType & imat = mat.GetVnlMatrix();
-    for ( i = 0; i < NDimensions; i++ )
+    for ( unsigned int i = 0; i < NDimensions; i++ )
       {
       if ( m_MatrixScale[i] != 0 && m_Scale[i] != 0 )
         {

Reply to: