The following makes sure to guard the modref query in VN on a
pointer typed argument.
2022-03-08 Richard Biener <rguenther@suse.de>
PR tree-optimization/104825
* tree-ssa-sccvn.cc (visit_reference_op_call): Properly
guard modref get_ao_ref on a pointer typed argument.
* gcc.dg/torture/pr104825.c: New testcase.
--- /dev/null
+/* { dg-do compile } */
+/* { dg-additional-options "-Wno-stringop-overread" } */
+
+int foo (fmt)
+char* fmt;
+{
+ return (__builtin_strchr (fmt, '*') != 0
+ || __builtin_strchr (fmt, 'n') != 0);
+}
+void bar ()
+{
+ if (foo (1))
+ __builtin_abort ();
+}
{
accesses.quick_grow (accesses.length () + 1);
ao_ref *r = &accesses.last ();
- if (!access_node.get_ao_ref (stmt, r))
+ tree arg = access_node.get_call_arg (stmt);
+ if (!POINTER_TYPE_P (TREE_TYPE (arg))
+ || !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