]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/103987 - guard DSE modref query
authorRichard Biener <rguenther@suse.de>
Tue, 18 Jan 2022 12:26:22 +0000 (13:26 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 18 Jan 2022 13:33:01 +0000 (14:33 +0100)
This adds a missing guard for a pointer to the DSE modref query,
otherwise we can end up invoking APIs desired to only work on
pointers on non-pointers when there are mismatches between declared
and actual arguments of functions in the program.

2022-01-18  Richard Biener  <rguenther@suse.de>

PR tree-optimization/103987
* tree-ssa-dse.cc (dse_optimize_call): Properly guard modref
query with a pointer check.

* gcc.dg/torture/pr103987.c: New testcase.

gcc/testsuite/gcc.dg/torture/pr103987.c [new file with mode: 0644]
gcc/tree-ssa-dse.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr103987.c b/gcc/testsuite/gcc.dg/torture/pr103987.c
new file mode 100644 (file)
index 0000000..6bfc768
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+
+void foo();
+
+void bar(int i)
+{
+  foo (i);
+}
+
+void foo(int *p)
+{
+  *p = 0;
+}
index ed73bee932ae9ef88990d1d0b6f159b5fba3d238..47997df21255ceb6e11456eb5fbe9993d210d0cd 100644 (file)
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cgraph.h"
 #include "ipa-modref-tree.h"
 #include "ipa-modref.h"
+#include "target.h"
 
 /* This file implements dead store elimination.
 
@@ -1190,10 +1191,12 @@ dse_optimize_call (gimple_stmt_iterator *gsi, sbitmap live_bytes)
        {
          tree arg = access_node.get_call_arg (stmt);
 
-         if (!arg)
+         if (!arg || !POINTER_TYPE_P (TREE_TYPE (arg)))
            return false;
 
-         if (integer_zerop (arg) && flag_delete_null_pointer_checks)
+         if (integer_zerop (arg)
+             && !targetm.addr_space.zero_address_valid
+                   (TYPE_ADDR_SPACE (TREE_TYPE (arg))))
            continue;
 
          ao_ref ref;