This is the mail archive of the gcc-patches@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]

Re: Fix PR 19643. [ Was Re: Speedup CSE by 5% ]


Roger Sayle wrote:
> Hi Jeff,
[...]
>>This fixes PR 19643 in the obvious way.
> 
> 
> Alas, not so "obvious" as this is clearly incorrect.
> 
> 
> 
>>!       /* 0 % X is always zero as is X % 1.  */
>>!       if (integer_zerop (arg0) || integer_onep (arg1))
>>         return omit_one_operand (type, integer_zero_node, arg0);
> 
> 
> If the first argument is integer_zerop, then its the second operand
> arg1 that needs to be evaluated for potential side-effects before
> returning zero.
> 
> i.e. something closer might be
> 
>         if (integer_onep (arg1))
>           return omit_one_operand (type, integer_zero_node, arg0);
> 	if (integer_zerop (arg0))
> 	  return omit_one_operand (type, integer_zero_node, arg1);
> 
> 
> We should add a "0 % x++" testcase to the testsuite (if there isn't
> one already).  p.s. don't forget to list the target-triple that you
> bootstrap and regression test on when you post a correction.
> 
> I'm still investigating possible java front-end interactions and
> whether gcj/bytecode requires the evaluation of "0 % 0" to throw
> a java.lang.ArithmeticException.

Indeed this causes a Jacks testsuite regression for GCJ.
Specifically testcase 15.28-div0-2.

Since "0 % 0" is undefined, it is not a compile-time constant
expression and must be complained about.

In fact, this is a regression even for C w.r.t. GCC 3.4.3:

/tmp > cat x.c
int foo(int x)
{
  switch(x)
  {
  case 0 % 0:
    return 1;
  default:
    return 2;
  }
}

/tmp > gcc --syntax-only -Wall x.c
x.c: In function `foo':
x.c:5: warning: division by zero
x.c:5: error: case label does not reduce to an integer constant

/tmp > /extra/src/gcc/build/gcc/xgcc -B/extra/src/gcc/build/gcc/
--syntax-only -Wall x.c
x.c: In function 'foo':
x.c:5: warning: division by zero

Thanks,
Ranjit.

-- 
Ranjit Mathew       Email: rmathew AT gmail DOT com

Bangalore, INDIA.     Web: http://ranjitmathew.hostingzero.com/


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