This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/19606] wrong code for arith.expr: (((unsigned int)(signed int) a ) / 2LL) with signed char a=-4
- From: "kazu at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Jan 2006 21:44:12 -0000
- Subject: [Bug c/19606] wrong code for arith.expr: (((unsigned int)(signed int) a ) / 2LL) with signed char a=-4
- References: <bug-19606-5884@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #7 from kazu at gcc dot gnu dot org 2006-01-15 21:44 -------
In the original test case, TRUNC_DIV_EXPR is used, but we can also use
TRUNC_MOD_EXPR to cause a similar problem. See below.
#include <stdio.h>
signed char a = -4;
#if 0
#define CALC(A) (((unsigned int) (signed int) (A)) / 2LL)
#else
#define CALC(A) (((unsigned int) (signed int) (A)) % 5LL)
#endif
int
test ()
{
return CALC (a);
}
int
main (void)
{
int r;
r = test ();
printf ("test output: %#x == %d %x %x\n",
r, r, (r == 0x7ffffffe), (r == 0xfffffffe));
if (r == CALC ((signed char) -4))
printf ("test successful\n");
else
printf ("test failed\n");
return 0;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19606