From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27255 invoked by alias); 25 Jul 2014 10:36:14 -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 26889 invoked by uid 48); 25 Jul 2014 10:36:09 -0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/61893] Constant folding inhibits trapping with -ftrapv Date: Fri, 25 Jul 2014 10:36:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.9.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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-07/txt/msg01688.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61893 --- Comment #1 from Richard Biener --- Fixed by sth like Index: fold-const.c =================================================================== --- fold-const.c (revision 212388) +++ fold-const.c (working copy) @@ -1121,7 +1121,12 @@ STRIP_NOPS (arg2); if (TREE_CODE (arg1) == INTEGER_CST) - return int_const_binop (code, arg1, arg2); + { + tree res = int_const_binop (code, arg1, arg2); + if (res && TYPE_OVERFLOW_TRAPS (TREE_TYPE (arg1)) && TREE_OVERFLOW (res)) + return NULL_TREE; + return res; + } if (TREE_CODE (arg1) == REAL_CST) {