This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Add st[pr]ncpy to stmt_kills_ref_p
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 29 Apr 2017 09:17:12 +0200 (CEST)
- Subject: Add st[pr]ncpy to stmt_kills_ref_p
- Authentication-results: sourceware.org; auth=none
Hello,
this patch seems rather trivial, once one knows that those functions
always write exactly n characters (they fill with 0 as needed at the end).
Bootstrap+regtest on powerpc64le-unknown-linux-gnu.
2017-05-02 Marc Glisse <marc.glisse@inria.fr>
PR tree-optimization/80487
gcc/
* tree-ssa-alias.c (stmt_kills_ref_p): Handle stpncpy and strncpy.
gcc/testsuite/
* gcc.dg/tree-ssa/strncpy-1.c: New file.
--
Marc Glisse
Index: gcc/testsuite/gcc.dg/tree-ssa/strncpy-1.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/strncpy-1.c (nonexistent)
+++ gcc/testsuite/gcc.dg/tree-ssa/strncpy-1.c (working copy)
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized" } */
+
+void sink (void*);
+
+void f (const char *s)
+{
+ char a[256];
+
+ __builtin_memset (a, 0, sizeof a); // redundant memset
+ __builtin_strncpy (a, s, sizeof a);
+
+ sink (a);
+}
+
+/* { dg-final { scan-tree-dump-not "memset" "optimized" } } */
Index: gcc/tree-ssa-alias.c
===================================================================
--- gcc/tree-ssa-alias.c (revision 247405)
+++ gcc/tree-ssa-alias.c (working copy)
@@ -2531,20 +2531,22 @@ stmt_kills_ref_p (gimple *stmt, ao_ref *
}
case BUILT_IN_MEMCPY:
case BUILT_IN_MEMPCPY:
case BUILT_IN_MEMMOVE:
case BUILT_IN_MEMSET:
case BUILT_IN_MEMCPY_CHK:
case BUILT_IN_MEMPCPY_CHK:
case BUILT_IN_MEMMOVE_CHK:
case BUILT_IN_MEMSET_CHK:
+ case BUILT_IN_STRNCPY:
+ case BUILT_IN_STPNCPY:
{
/* For a must-alias check we need to be able to constrain
the access properly. */
if (ref->max_size == -1)
return false;
tree dest = gimple_call_arg (stmt, 0);
tree len = gimple_call_arg (stmt, 2);
if (!tree_fits_shwi_p (len))
return false;
tree rbase = ref->base;