From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 42901 invoked by alias); 25 Jul 2017 14:41:14 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 42740 invoked by uid 89); 25 Jul 2017 14:41:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Strict, sk:operati, javier, rcode X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Jul 2017 14:41:06 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 6F1F581342 for ; Tue, 25 Jul 2017 16:41:03 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ga6dp84E_VNb for ; Tue, 25 Jul 2017 16:41:03 +0200 (CEST) Received: from arcturus.home (ADijon-653-1-262-51.w86-197.abo.wanadoo.fr [86.197.15.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id A790B81340 for ; Tue, 25 Jul 2017 16:41:02 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: Fix thinko in gimple_assign_set_rhs_with_ops Date: Tue, 25 Jul 2017 14:41:00 -0000 Message-ID: <2663014.h6Leadj67V@arcturus.home> User-Agent: KMail/4.14.10 (Linux/3.16.7-53-desktop; KDE/4.14.9; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart6229862.coGmWJD5QY" Content-Transfer-Encoding: 7Bit X-SW-Source: 2017-07/txt/msg01581.txt.bz2 This is a multi-part message in MIME format. --nextPart6229862.coGmWJD5QY Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Content-length: 2929 The attached fix to the Ada front-end introduces a regression in the ACATS testsuite for cb4009a. The backtrace is: #0 operation_could_trap_helper_p(tree_code, bool, bool, bool, bool, tree_node*, bool*) () at /home/eric/gnat/gnat-head/src/gcc/tree-eh.c:2439 #1 0x00000000012946d7 in stmt_could_throw_1_p (stmt=) at /home/eric/gnat/gnat-head/src/gcc/tree-eh.c:2759 #2 stmt_could_throw_p(gimple*) [clone .part.186] () at /home/eric/gnat/gnat-head/src/gcc/tree-eh.c:2809 #3 0x0000000001295f28 in stmt_could_throw_p (stmt=0x7ffff6c5d420) at /home/eric/gnat/gnat-head/src/gcc/tree-eh.c:2924 #4 maybe_clean_or_replace_eh_stmt (old_stmt=old_stmt@entry=0x7ffff6c565d8, new_stmt=new_stmt@entry=0x7ffff6c5d420) at /home/eric/gnat/gnat-head/src/gcc/tree-eh.c:2908 #5 0x0000000000fd8a0b in gsi_replace(gimple_stmt_iterator*, gimple*, bool) () at /home/eric/gnat/gnat-head/src/gcc/gimple-iterator.c:447 #6 0x0000000000fd14af in gimple_assign_set_rhs_with_ops(gimple_stmt_iterator*, tree_code, tree_node*, tree_node*, tree_node*) () at /home/eric/gnat/gnat-head/src/gcc/gimple.c:1616 #7 0x0000000000fe7af7 in replace_stmt_with_simplification (inplace=false, seq=0x7fffffffd818, ops=0x7fffffffd820, rcode=..., gsi=0x7fffffffd8e0) at /home/eric/gnat/gnat-head/src/gcc/gimple-fold.c:4151 #8 fold_stmt_1(gimple_stmt_iterator*, bool, tree_node* (*)(tree_node*)) () at /home/eric/gnat/gnat-head/src/gcc/gimple-fold.c:4462 #9 0x0000000000fe961a in fold_stmt (gsi=gsi@entry=0x7fffffffd8e0, valueize=valueize@entry=0x1331170 ) at /home/eric/gnat/gnat-head/src/gcc/gimple-fold.c:4689 The folding is turning a TRUNC_DIV_EXPR into a COND_EXPR and the code does: /* If the new CODE needs more operands, allocate a new statement. */ if (gimple_num_ops (stmt) < new_rhs_ops + 1) { tree lhs = gimple_assign_lhs (stmt); gimple *new_stmt = gimple_alloc (gimple_code (stmt), new_rhs_ops + 1); memcpy (new_stmt, stmt, gimple_size (gimple_code (stmt))); gimple_init_singleton (new_stmt); gsi_replace (gsi, new_stmt, true); stmt = new_stmt; /* The LHS needs to be reset as this also changes the SSA name on the LHS. */ gimple_assign_set_lhs (stmt, lhs); } i.e it asks gsi_replace to update EH info, which doesn't work since the new statement is dummy at this point. Fixed by passing false instead of true. Bootstrapped/regtested on x86_64-suse-linux, applied on mainline as obvious. 2017-07-25 Eric Botcazou * gimple.c (gimple_assign_set_rhs_with_ops): Do not ask gsi_replace to update EH info here. 2017-07-25 Javier Miranda ada/ * checks.adb (Apply_Divide_Checks): Ensure that operands are not evaluated twice. 2017-07-25 Eric Botcazou testsuite/ * gnat.dg/opt66.adb: New test. -- Eric Botcazou --nextPart6229862.coGmWJD5QY Content-Disposition: attachment; filename="p.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="p.diff" Content-length: 1334 Index: gimple.c =================================================================== --- gimple.c (revision 250379) +++ gimple.c (working copy) @@ -1613,7 +1613,7 @@ gimple_assign_set_rhs_with_ops (gimple_stmt_iterat gimple *new_stmt = gimple_alloc (gimple_code (stmt), new_rhs_ops + 1); memcpy (new_stmt, stmt, gimple_size (gimple_code (stmt))); gimple_init_singleton (new_stmt); - gsi_replace (gsi, new_stmt, true); + gsi_replace (gsi, new_stmt, false); stmt = new_stmt; /* The LHS needs to be reset as this also changes the SSA name Index: ada/checks.adb =================================================================== --- ada/checks.adb (revision 250379) +++ ada/checks.adb (working copy) @@ -1818,6 +1818,13 @@ package body Checks is and then ((not LOK) or else (Llo = LLB)) then + -- Ensure that expressions are not evaluated twice (once + -- for their runtime checks and once for their regular + -- computation). + + Force_Evaluation (Left, Mode => Strict); + Force_Evaluation (Right, Mode => Strict); + Insert_Action (N, Make_Raise_Constraint_Error (Loc, Condition => --nextPart6229862.coGmWJD5QY Content-Disposition: attachment; filename="opt66.adb" Content-Transfer-Encoding: 7Bit Content-Type: text/x-adasrc; charset="UTF-8"; name="opt66.adb" Content-length: 205 -- { dg-do compile } -- { dg-options "-O" } procedure Opt66 (I : Integer) is E : exception; begin if I = 0 then raise E; end if; Opt66 (I - I / abs (I)); exception when others => null; end; --nextPart6229862.coGmWJD5QY--