https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101508
Bug ID: 101508 Summary: Possible undefined behaviour in cpp program using "unsigned" type starting from GCC 9 Product: gcc Version: 10.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pnarsing at mathworks dot com Target Milestone: --- Hi Team, I'm observing an optimization issue while compiling with GCC 10.3 . On investigating figured that issue is reproducible in GCC 9 as well . This can be reproduced by simple test code mentioned below : ------------------------------------------------------ using int_type = unsigned int; // works without "unsigned" int_type constexpr start{0}; // works if >= 1 int_type constexpr stop{3}; // works if <= 2 int_type constexpr mult{2}; // works if != 2 int main() { int result = 0; for(int_type aa = start; aa < stop; ++aa) { int_type const bb = aa * mult; // works if volatile if (aa > bb) { return 99; } ++result; } return result; // should be == stop } ---------------------------------------------------------------- This code snippet returns 99 instead of 3 . You can check the following link to see the issue reproducibility: https://godbolt.org/z/zd79PPKfn Modifying compiler option to -O1 and -Og avoids the issue.