Skip to content

Iterations invoke undefined behavior #5222

Open
@jhlegarreta

Description

@jhlegarreta

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:BugInconsistencies or issues which will cause an incorrect result under some or all circumstances

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions