ITK icon indicating copy to clipboard operation
ITK copied to clipboard

Iterations invoke undefined behavior

Open jhlegarreta opened this issue 9 months ago • 0 comments

Description

Several warnings, e.g.

 warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]

are suggesting that for some assignments across loops, e.g.

 point[j] += displacement[j];

the result may result in undefined behavior.

Steps to Reproduce

  1. Clone ITK
  2. Configure and build
  3. Run tests

Expected behavior

No warnings are present/no undefined behavior is present across the code base.

Actual behavior

Undefined behavior is present:

Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx:308:18:
warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
  308 |         point[j] += displacement[j];
      |                  ^

and

Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx:338:18:
warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
  338 |         point[j] += displacement[j];
      |

and

Modules/Registration/PDEDeformable/include/itkESMDemonsRegistrationFunction.hxx:331:22:
warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
  331 |       mappedPoint[j] += it.GetCenterPixel()[j];
      |

and

Modules/Registration/PDEDeformable/include/itkESMDemonsRegistrationFunction.hxx:383:19:
warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
  383 |         update[j] = factor * usedGradientTimes2[j];
      |

Reproducibility

%100

Versions

HEAD (at this point, ee1f1fc)

Environment

Ubuntu-22.04-gcc11.2-Rel-Python

Additional Information

https://open.cdash.org/viewBuildError.php?type=1&buildid=10193131

PR #5166 unsuccessfully claimed to fix these warnings.

jhlegarreta avatar Feb 06 '25 16:02 jhlegarreta