From: Eric Botcazou <ebotcazou@adacore.com>
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 [thread overview]
Message-ID: <2663014.h6Leadj67V@arcturus.home> (raw)
[-- Attachment #1: Type: text/plain, Size: 2929 bytes --]
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=<optimized out>)
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 <fwprop_ssa_val(tree)>)
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 <ebotcazou@adacore.com>
* gimple.c (gimple_assign_set_rhs_with_ops): Do not ask gsi_replace
to update EH info here.
2017-07-25 Javier Miranda <miranda@adacore.com>
ada/
* checks.adb (Apply_Divide_Checks): Ensure that operands are not
evaluated twice.
2017-07-25 Eric Botcazou <ebotcazou@adacore.com>
testsuite/
* gnat.dg/opt66.adb: New test.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 1334 bytes --]
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 =>
[-- Attachment #3: opt66.adb --]
[-- Type: text/x-adasrc, Size: 205 bytes --]
-- { 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;
next reply other threads:[~2017-07-25 14:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-25 14:41 Eric Botcazou [this message]
2017-07-26 7:52 ` Richard Biener
2017-07-28 7:37 ` Eric Botcazou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2663014.h6Leadj67V@arcturus.home \
--to=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).