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.

Reply via email to