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 a2082928881091ebab4b243dc50fb398f2f88287..3e3474701d5c1fcf8d161e813dfe46d2988a16eb 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 59f1a31bfd77bf37f01e388ff977e82214207842..2d3d02b018cd138962723f531e4b5f4f62225c7d 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 0dcb273e5c2e236f29a992530d4dafd9cda34958..8cab159916a776e3a9f50de68d72313596278338 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.  */