From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32491 invoked by alias); 21 Aug 2014 11:04:20 -0000 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 Received: (qmail 32393 invoked by uid 48); 21 Aug 2014 11:04:08 -0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/62175] [4.9/5 Regression] Internal compiler error in gimplify_modify_expr gimplify.c:4616 Date: Thu, 21 Aug 2014 11:04:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.9.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.9.2 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-08/txt/msg01452.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62175 --- Comment #6 from Richard Biener --- Ok, so we try to generate a memset from a loop with the number of iterations being (long int) (_3 + 1) >= (long int) _7 + 1 ? ((unsigned long) (_3 + 1) - (unsigned long) _7) - 1 : 0 as this has conditionals it doesn't survive gimplification (gimplification turns it into control-flow). Not sure how other passes avoid running into this. We run into this gimplifying issue because of: if (gimplify_ctxp->allow_rhs_cond_expr /* If either branch has side effects or could trap, it can't be evaluated unconditionally. */ && !TREE_SIDE_EFFECTS (then_) && !generic_expr_could_trap_p (then_) && !TREE_SIDE_EFFECTS (else_) && !generic_expr_could_trap_p (else_)) return gimplify_pure_cond_expr (expr_p, pre_p); that is, gimplification is afraid of evaluating both COND_EXPR results unconditionally because of -ftrapv. [of course those are compiler-generated expressions and shouldn't have -ftrapv applied, but that's not possible to tell right now so it would mean creating unsigned expressions only] Here _3 + 1 can trap. We could short-cicuit the above by gimplify_ctxp->into_ssa but that may cause these ICEs to turn into wrong-code if we ever bogously generate trapping expressions unconditonally. It is tree-ssa-loop-niter.c:expand_simple_operations which builds up this expression. We could guard that properly to not expand possibly trapping statements. That's probably the safest and most reliable way of avoiding this bug. Index: gcc/tree-ssa-loop-niter.c =================================================================== --- gcc/tree-ssa-loop-niter.c (revision 214258) +++ gcc/tree-ssa-loop-niter.c (working copy) @@ -1633,6 +1633,9 @@ expand_simple_operations (tree expr) case PLUS_EXPR: case MINUS_EXPR: + if (TYPE_OVERFLOW_TRAPS (TREE_TYPE (expr))) + return expr; + /* Fallthru. */ case POINTER_PLUS_EXPR: /* And increments and decrements by a constant are simple. */ e1 = gimple_assign_rhs2 (stmt);