[Bug tree-optimization/104196] [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jan 24 00:37:45 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104196

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is one which shows the issue just in case fold gets in the way:
int a = 6;
int main() {
    for (;;)
    {
        int c = 111;
        if (a < 0)
            c = -__INT_MAX__ - a;
        int b = a;
        if (a >= 0 || c > 0)
            b = 0;
        if (b != 4096 - __INT_MAX__) {
            if (a < 6)
                __builtin_abort ();
            return 0;
        }
    }
}

The main point is the undefined behavior of -__INT_MAX__ - a when a is not less
than 0 which is not true here as a is always 6.

Also for some reason using the C++ front-end also works around the issue ...
(but I don't see how though).


More information about the Gcc-bugs mailing list