This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/40757] gcc 4.4.0 miscompiles mpfr-2.4.1
- From: "jakub at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Jul 2009 07:49:22 -0000
- Subject: [Bug c/40757] gcc 4.4.0 miscompiles mpfr-2.4.1
- References: <bug-40757-16207@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #17 from jakub at gcc dot gnu dot org 2009-07-17 07:49 -------
Try:
typedef __SIZE_TYPE__ size_t;
extern void *memset (void *, const void *, size_t);
extern void abort (void);
volatile size_t i = 0x80000000U, j = 0x80000000U;
char buf[16];
int main (void)
{
if (sizeof (size_t) != 4)
return 0;
buf[0] = 6;
memset (buf, 0, i + j);
if (buf[0] != 6)
abort ();
return 0;
}
In 32-bit code, size_t is 32-bit, memset is called with buf, 0, 0 arguments,
but the %o2 register passed to it doesn't contain 0, but 0x100000000. That is
fine, this is 32-bit code, so the uppermost bits are always undefined. But
when 32-bit memset uses brnz %o2, ... instruction, it needs to first
zero-extend it to 64-bits, as brnz operates on all 64 bits only. Or not use
brnz, but compare and be %icc, ...
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40757