From ad665deeafd31238b537139385e1e80b40c10e0c Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 23 Aug 2021 09:57:05 +0200 Subject: tree-optimization/79334 - avoid PRE of possibly trapping array-ref This replicates tree-eh.c in_array_bound_p into VNs vn_reference_may_trap to fix hoisting of a possibly trapping ARRAY_REF across a call that might not return. 2021-08-23 Richard Biener PR tree-optimization/79334 * tree-ssa-sccvn.c (copy_reference_ops_from_ref): Record a type also for COMPONENT_REFs. (vn_reference_may_trap): Check ARRAY_REF with constant index against the array domain. * gcc.dg/torture/pr79334-0.c: New testcase. * gcc.dg/torture/pr79334-1.c: Likewise. --- gcc/testsuite/gcc.dg/torture/pr79334-0.c | 23 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/torture/pr79334-1.c | 1 + 2 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr79334-0.c create mode 100644 gcc/testsuite/gcc.dg/torture/pr79334-1.c (limited to 'gcc/testsuite/gcc.dg') diff --git a/gcc/testsuite/gcc.dg/torture/pr79334-0.c b/gcc/testsuite/gcc.dg/torture/pr79334-0.c new file mode 100644 index 0000000..fa45a6d --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr79334-0.c @@ -0,0 +1,23 @@ +/* { dg-do run } */ +/* { dg-additional-sources "pr79334-1.c" } */ + +extern int d[][8]; + +static void __attribute__((noinline)) +func_that_exits (int flag) +{ + if (!flag) + __builtin_exit (0); +} + +int main () +{ + int e = 0; + while (1) + { + func_that_exits (e); + /* We do not know whether d[1024][0] will trap. */ + e = d[1024][0]; + } + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr79334-1.c b/gcc/testsuite/gcc.dg/torture/pr79334-1.c new file mode 100644 index 0000000..b1c8a27 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr79334-1.c @@ -0,0 +1 @@ +int d[1][8]; -- cgit v1.1