From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16319 invoked by alias); 1 Dec 2006 02:37:58 -0000 Received: (qmail 16293 invoked by uid 48); 1 Dec 2006 02:37:50 -0000 Date: Fri, 01 Dec 2006 02:37:00 -0000 Message-ID: <20061201023750.16292.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c/19976] integer division by zero in subexpression should be overflow In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "manu at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-12/txt/msg00083.txt.bz2 ------- 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