This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: _Bool and trap representations
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: Alexander Cherepanov <ch3root at openwall dot com>, Joseph Myers <joseph at codesourcery dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, Martin Sebor <msebor at gmail dot com>, Richard Biener <rguenther at suse dot de>
- Date: Wed, 15 Jun 2016 13:11:22 +0000
- Subject: Re: _Bool and trap representations
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=softfail (sender IP is 25.152.0.55) smtp.mailfrom=hotmail.de; gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=hotmail.de;
Hi,
I modified Aexander's test case a bit, and found something
unexpected, which looks like a GCC-BUG to me:
cat test.c
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
long double d0, d;
memcpy(&d0, "\x00\x00\x00\x00\x00\x00\x00\x00\xff\x3f\x00\x00\x00\x00\x00\x00", sizeof d0);
// d = d0;
memcpy(&d, &d0, sizeof d0);
// if (memcmp(&d, &d0, sizeof d))
// abort();
printf("d = %Lf\n", d);
for (unsigned char *p = (unsigned char *)&d + sizeof d; p > (unsigned char *)&d;)
printf("%02x ", *--p);
printf("\n");
}
// EOF
gcc -O3 test.c && ./a.out
d = 0.000000
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
but, when I un-comment the memcmp the test case shows the expected
result:
d = 0.000000
00 00 00 00 00 00 3f ff 00 00 00 00 00 00 00 00
gcc-Version 7.0.0 20160613 (experimental) (GCC)
Would'nt you agree, that if we use memcpy it should be possible
to preserve denormalized or otherwise invalid bit patterns?
And why should the memcmp have an influence on the memcpy?
Bernd.