]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/114246 - invalid call argument from DSE
authorRichard Biener <rguenther@suse.de>
Wed, 6 Mar 2024 08:02:31 +0000 (09:02 +0100)
committerRichard Biener <rguenther@suse.de>
Wed, 6 Mar 2024 09:27:34 +0000 (10:27 +0100)
The following makes sure to strip type conversions added by
build_fold_addr_expr before placing the result in a call argument.

PR tree-optimization/114246
* tree-ssa-dse.cc (increment_start_addr): Strip useless
type conversions from the adjusted address.

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

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr114246.c b/gcc/testsuite/gcc.dg/torture/pr114246.c
new file mode 100644 (file)
index 0000000..eb20db5
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-w" } */
+
+int a, b;
+
+void
+foo (void)
+{
+  __builtin_memcpy (&a, (char *)&b - 1, 2);
+  __builtin_memcpy (&a, &b, 1);
+}
index 7c348516ddfa8550b813cd792fbb8ea162157723..fce4fc76a56102fbe660d6e623698d5e8cc981a5 100644 (file)
@@ -49,6 +49,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfgloop.h"
 #include "tree-data-ref.h"
 #include "internal-fn.h"
+#include "tree-ssa.h"
 
 /* This file implements dead store elimination.
 
@@ -658,6 +659,7 @@ increment_start_addr (gimple *stmt, tree *where, int increment)
                                              *where,
                                              build_int_cst (ptr_type_node,
                                                             increment)));
+  STRIP_USELESS_TYPE_CONVERSION (*where);
 }
 
 /* STMT is builtin call that writes bytes in bitmap ORIG, some bytes are dead