From 27bfd13437c773a050f532ed164907de54b5a64f Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 7 Apr 2022 09:16:50 +0200 Subject: [PATCH] tree-optimization/105185 - simplify modref query in SCCVN This simplifies the modref query for calls in SCCVN again after r12-8019-g4be08315124281, avoiding an ICE when the modref analyzed access lacks an actual argument on the caller side. It effectively reverts r12-7531-gdc46350d44c294. 2022-04-07 Richard Biener PR tree-optimization/105185 * tree-ssa-sccvn.cc (visit_reference_op_call): Simplify modref query again. * gcc.dg/torture/pr105185.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr105185.c | 13 +++++++++++++ gcc/tree-ssa-sccvn.cc | 5 ++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr105185.c diff --git a/gcc/testsuite/gcc.dg/torture/pr105185.c b/gcc/testsuite/gcc.dg/torture/pr105185.c new file mode 100644 index 0000000..6ab3236 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr105185.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +int foo (fmt) +char* fmt; +{ + return (__builtin_strchr (fmt, '*') != 0 + || __builtin_strchr (fmt, 'n') != 0); +} +void bar () +{ + if (foo ()) + __builtin_abort (); +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 66b4fc2..d4d0aba 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -5140,12 +5140,11 @@ visit_reference_op_call (tree lhs, gcall *stmt) { accesses.quick_grow (accesses.length () + 1); ao_ref *r = &accesses.last (); - tree arg = access_node.get_call_arg (stmt); - if (!POINTER_TYPE_P (TREE_TYPE (arg)) - || !access_node.get_ao_ref (stmt, r)) + if (!access_node.get_ao_ref (stmt, r)) { /* Initialize a ref based on the argument and unknown offset if possible. */ + tree arg = access_node.get_call_arg (stmt); if (arg && TREE_CODE (arg) == SSA_NAME) arg = SSA_VAL (arg); if (arg -- 2.7.4