public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7531] tree-optimization/104825 - guard modref query
@ 2022-03-08 8:56 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-03-08 8:56 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:dc46350d44c2949ec38deb028960f8040f8e8e5d
commit r12-7531-gdc46350d44c2949ec38deb028960f8040f8e8e5d
Author: Richard Biener <rguenther@suse.de>
Date: Tue Mar 8 08:42:58 2022 +0100
tree-optimization/104825 - guard modref query
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.
Diff:
---
gcc/testsuite/gcc.dg/torture/pr104825.c | 14 ++++++++++++++
gcc/tree-ssa-sccvn.cc | 5 +++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/torture/pr104825.c b/gcc/testsuite/gcc.dg/torture/pr104825.c
new file mode 100644
index 00000000000..7affacc2094
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr104825.c
@@ -0,0 +1,14 @@
+/* { 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 ();
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index d4d0aba880c..66b4fc21f5b 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -5140,11 +5140,12 @@ visit_reference_op_call (tree lhs, gcall *stmt)
{
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-03-08 8:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 8:56 [gcc r12-7531] tree-optimization/104825 - guard modref query Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).