This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/19606] wrong code for arith.expr: (((unsigned int)(signed int) a ) / 2LL) with signed char a=-4



------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]