Error at division by constant zero

Andrew Haley aph@cambridge.redhat.com
Fri Aug 23 02:13:00 GMT 2002


Unruh, Erwin writes:

 > When dividing an integer by constant zero, the GCC does emit a library call to
 > the corresponding routine. On Sparc this is .rem or .div, on Linux this might be
 > __modsi3 or __divsi3.
 > 
 > I think this is an error in expand_divmod. EXACT_POWER_OF_2_OR_ZERO_P gives
 > true. So we think we could use a shift optab.

For division by zero?  How?

Division by zero is an undefined operation in C - see ISO 9899 Section
6.3.5.  So, in theory we can do anything.  But, what is the most
useful "anything" we can do?  We have chosen to preserve division by
zero so that if the processor has a divide overflow trap we'll get one
at runtime.  Also, some languages (such as Java) can trap divide
overlows overflow and we need that behaviour.

Andrew.



More information about the Gcc mailing list