[Bug middle-end/94103] Wrong optimization: reading value of a variable changes its representation for optimizer

ch3root at openwall dot com gcc-bugzilla@gcc.gnu.org
Mon Mar 9 17:46:10 GMT 2020


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

--- Comment #1 from Alexander Cherepanov <ch3root at openwall dot com> ---
Example with decimal floating-point:

----------------------------------------------------------------------
#include <string.h>
#include <stdio.h>

int main()
{
    _Decimal32 x = 9999999; // maximum significand
    unsigned u;

    memcpy(&u, &x, sizeof u);
    printf("%#08x\n", u);

    ++*(unsigned char *)&x; // create non-canonical representation of 0
    (void)-x;

    memcpy(&u, &x, sizeof u);
    printf("%#08x\n", u);
}
----------------------------------------------------------------------
$ gcc -std=c2x -pedantic -Wall -Wextra test.c && ./a.out
0x6cb8967f
0x6cb89680
$ gcc -std=c2x -pedantic -Wall -Wextra -O3 test.c && ./a.out
0x6cb8967f
0x32800000
----------------------------------------------------------------------
gcc x86-64 version: gcc (GCC) 10.0.1 20200305 (experimental)
----------------------------------------------------------------------

Unoptimized results are right, optimized -- wrong.


More information about the Gcc-bugs mailing list