Add st[pr]ncpy to stmt_kills_ref_p
authorMarc Glisse <marc.glisse@inria.fr>
Sat, 29 Apr 2017 14:39:25 +0000 (16:39 +0200)
committerMarc Glisse <glisse@gcc.gnu.org>
Sat, 29 Apr 2017 14:39:25 +0000 (14:39 +0000)
2017-04-29  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.

From-SVN: r247408

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/strncpy-1.c [new file with mode: 0644]
gcc/tree-ssa-alias.c

index a208292..3e34747 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-29  Marc Glisse  <marc.glisse@inria.fr>
+
+       PR tree-optimization/80487
+       * tree-ssa-alias.c (stmt_kills_ref_p): Handle stpncpy and strncpy.
+
 2017-04-29  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
 
        PR tree-optimization/79697
index 59f1a31..2d3d02b 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-29  Marc Glisse  <marc.glisse@inria.fr>
+
+       PR tree-optimization/80487
+       * gcc.dg/tree-ssa/strncpy-1.c: New file.
+
 2017-04-29  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
 
        PR tree-optimization/79697
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/strncpy-1.c b/gcc/testsuite/gcc.dg/tree-ssa/strncpy-1.c
new file mode 100644 (file)
index 0000000..751eaea
--- /dev/null
@@ -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 0dcb273..8cab159 100644 (file)
@@ -2538,6 +2538,8 @@ stmt_kills_ref_p (gimple *stmt, ao_ref *ref)
          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.  */