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]

combine: division by zero


Combine removes mod insns whose divisor is const 0.  

While this may be acceptable for C, it isn't for some other languages
(certainly Java, perhaps also Ada) and the insn should be retained so
that it can trigger a divide overflow signal at run time.

In any case, we don't know how many bits the result will have, so we
shouldn't presume anything.

This patch also corrects for the case of division by 0, as the size of
the result is unknown.

Andrew.

2001-06-14  Andrew Haley  <aph@cambridge.redhat.com>

	* combine.c (nonzero_bits): Don't optimize away division by zero.

Index: combine.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/combine.c,v
retrieving revision 1.183.2.5
diff -c -3 -p -r1.183.2.5 combine.c
*** combine.c	2001/05/27 10:31:42	1.183.2.5
--- combine.c	2001/06/14 19:47:38
*************** nonzero_bits (x, mode)
*** 8296,8313 ****
--- 8296,8321 ----
  	    result_low = low0 + low1;
  	    break;
  	  case DIV:
+ 	    if (width1 == 0)
+ 	      break;
  	    if (! op0_maybe_minusp && ! op1_maybe_minusp)
  	      result_width = width0;
  	    break;
  	  case UDIV:
+ 	    if (width1 == 0)
+ 	      break;
  	    result_width = width0;
  	    break;
  	  case MOD:
+ 	    if (width1 == 0)
+ 	      break;
  	    if (! op0_maybe_minusp && ! op1_maybe_minusp)
  	      result_width = MIN (width0, width1);
  	    result_low = MIN (low0, low1);
  	    break;
  	  case UMOD:
+ 	    if (width1 == 0)
+ 	      break;
  	    result_width = MIN (width0, width1);
  	    result_low = MIN (low0, low1);
  	    break;


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