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.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2022-04-07  Richard Biener  <rguent...@suse.de>

        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 00000000000..6ab32360de1
--- /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 66b4fc21f5b..d4d0aba880c 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.34.1

Reply via email to