This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/19976] integer division by zero in subexpression should be overflow
- From: "manu at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 1 Dec 2006 02:37:50 -0000
- Subject: [Bug c/19976] integer division by zero in subexpression should be overflow
- References: <bug-19976-230@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from manu at gcc dot gnu dot org 2006-12-01 02:37 -------
Hi Roger,
I am not sure how we are going to handle this.
First, the 1/0 is detected at int_const_binop at line 1509
--------------------------------------
case ROUND_DIV_EXPR:
if (int2h == 0 && int2l == 0)
return NULL_TREE;
--------------------------------------
I don't think we can return something different from NULL_TREE here. But we
cannot set TREE_OVERFLOW on a NULL_TREE.
Second, when int_const_binop returns to fold_binary we have another opportunity
to detect this at line 10026, but again we return NULL_TREE
----------------------------
case ROUND_DIV_EXPR:
case CEIL_DIV_EXPR:
case EXACT_DIV_EXPR:
if (integer_onep (arg1))
return non_lvalue (fold_convert (type, arg0));
if (integer_zerop (arg1))
return NULL_TREE;
----------------------------
Next, fold_build2_stat uses build2_stat to construct a valid tree node
(code=TRUNC_DIV_EXPR) but I don't see anything that can be used to detect that
there was a division by zero.
Finally, that tree node is simply omitted when folding 0*expr .
I really don't see how TREE_OVERFLOW could help here.
Unless we change 1/0 to be the same as INT_MAX+1, that is, a constant overflow.
However, then we will need something else to not warn about constant overflow
but only for division by zero.
Another option could be to build a TRUNC_DIV_EXPR node with TREE_OVERFLOW set
instead of returning NULL_TREE. But how and when?
I am running out of ideas...
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu dot org,
| |roger at eyesopen dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19976