Skip to content

COMP: Suppress GCC -Waggressive-loop-optimizations false positive#5966

Draft
hjmjohnson wants to merge 1 commit intoInsightSoftwareConsortium:mainfrom
hjmjohnson:fix-aggressive-loop-optimizations-warnings
Draft

COMP: Suppress GCC -Waggressive-loop-optimizations false positive#5966
hjmjohnson wants to merge 1 commit intoInsightSoftwareConsortium:mainfrom
hjmjohnson:fix-aggressive-loop-optimizations-warnings

Conversation

@hjmjohnson
Copy link
Member

Summary

  • Suppress GCC 11.4 false positive -Waggressive-loop-optimizations warnings in CDash nightly builds
  • Affects itkWarpImageFilter.hxx and itkESMDemonsRegistrationFunction.hxx where template-parameterized loops over FixedArray-based types trigger "iteration 2 invokes undefined behavior"
  • Suppressed via CTEST_CUSTOM_WARNING_EXCEPTION in CTestCustom.cmake.in

CDash Reference

Build 11129866 (Ubuntu-22.04-gcc11.4-Rel-Python, corista.kitware)

Test plan

  • CDash nightly builds no longer report these warnings
  • No new warnings introduced

🤖 Generated with Claude Code

GCC 11.4 emits "iteration 2 invokes undefined behavior" warnings
for template-parameterized loops over FixedArray-based types in
itkWarpImageFilter.hxx and itkESMDemonsRegistrationFunction.hxx.
These are false positives: the loop bound (ImageDimension) matches
the array size, but GCC's optimizer cannot prove this across
complex template instantiations.

Suppress via CTEST_CUSTOM_WARNING_EXCEPTION since ITK does not
use #pragma GCC diagnostic anywhere in the codebase.

CDash builds: 11129866 (Ubuntu-22.04-gcc11.4-Rel-Python)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added type:Compiler Compiler support or related warnings type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots labels Mar 18, 2026
@hjmjohnson
Copy link
Member Author

@blowekamp This was identified by running the updated version of the skill

@blowekamp
Copy link
Member

This looks reasonable. However unfortunately we tried a similar approach with the Eigen warnings and it did not work. In the following PR I updated to a simplified regex by removing the specific warning segment of the express, not ideal but it did suppress it.

https://github.com/InsightSoftwareConsortium/ITK/pull/5949/changes

Unfortunately there is some mystery to what will work.

I don't see any harm in this change, as long as we are keeping the expressions organized.

@N-Dekker
Copy link
Contributor

Interesting! Do you possibly have a link to the specific CDash page?

@blowekamp
Copy link
Member

https://open.cdash.org/builds/11129866/errors

@N-Dekker
Copy link
Contributor

N-Dekker commented Mar 18, 2026

https://open.cdash.org/builds/11129866/errors

Thanks @blowekamp So somewhere here:

PointType mappedPoint{};
this->GetFixedImage()->TransformIndexToPhysicalPoint(index, mappedPoint);
for (unsigned int j = 0; j < ImageDimension; ++j)
{
mappedPoint[j] += it.GetCenterPixel()[j];

Saying:

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

I guess iteration 2 is when j is 2, right? (So zero-based, 3D.) Honestly I don't understand the warning 🤷

I noticed that the warning even appears when no warnings are enabled at all!

At https://gcc.godbolt.org/z/esePs6ePE

int GetLargeInteger()
{
    int result{1};
    
    for (int i = 0; i < 4; ++i)
        result += i*1000000000;

    return result;
}

On GCC 15.2, having -std=c++17 -O2 (but nothing else, not even -Wall), output:

<source>: In function 'int GetLargeInteger()':
<source>:7:20: warning: iteration 3 invokes undefined behavior [-Waggressive-loop-optimizations]
    7 |         result += i*1000000000;
      |                   ~^~~~~~~~~~~
<source>:6:23: note: within this loop
    6 |     for (int i = 0; i < 4; ++i)
      |                     ~~^~~
Compiler returned: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:Compiler Compiler support or related warnings type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants