From 9348eb677eb9e113ae7889faa5466723a307941f Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 28 Feb 2018 13:40:41 +0000 Subject: [PATCH] re PR c/84607 (Side effects discarded in address computation inside 'if') 2018-02-28 Richard Biener PR middle-end/84607 * genmatch.c (capture_info::walk_match): Do not mark captured expressions without operands as expr_p given they act more like predicates and should be subject to "lost tail" side-effect preserving. * gcc.dg/pr84607.c: New testcase. From-SVN: r258061 --- gcc/ChangeLog | 8 ++++++++ gcc/genmatch.c | 6 +++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr84607.c | 16 ++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr84607.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8eedfcaaf82..d7f8754d2e9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2018-02-28 Richard Biener + + PR middle-end/84607 + * genmatch.c (capture_info::walk_match): Do not mark + captured expressions without operands as expr_p given + they act more like predicates and should be subject to + "lost tail" side-effect preserving. + 2018-02-28 Alexandre Oliva PR rtl-optimization/81611 diff --git a/gcc/genmatch.c b/gcc/genmatch.c index e2b2cbfe66c..be6efe3bf12 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -2104,7 +2104,11 @@ capture_info::walk_match (operand *o, unsigned toplevel_arg, if (c->what && (e = dyn_cast (c->what))) { - info[where].expr_p = true; + /* Zero-operand expression captures like ADDR_EXPR@0 are + similar as predicates -- if they are not mentioned in + the result we have to force them to have no side-effects. */ + if (e->ops.length () != 0) + info[where].expr_p = true; info[where].force_single_use |= e->force_single_use; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 252a33a00d4..eaa5041b18d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-02-28 Richard Biener + + PR middle-end/84607 + * gcc.dg/pr84607.c: New testcase. + 2018-02-28 Nathan Sidwell PR c++/84602 diff --git a/gcc/testsuite/gcc.dg/pr84607.c b/gcc/testsuite/gcc.dg/pr84607.c new file mode 100644 index 00000000000..710ee94f729 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr84607.c @@ -0,0 +1,16 @@ +/* { dg-do run } */ + +extern void exit(int); +extern void abort(void); +int a[10]; +int foo() +{ + exit (0); + return 0; +} +int main() +{ + if (&a[foo()]) + abort (); + return 0; +} -- 2.30.2