From: Marc Glisse Date: Sat, 29 Apr 2017 14:39:25 +0000 (+0200) Subject: Add st[pr]ncpy to stmt_kills_ref_p X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4212aecdf8c4bd99b681fcfc2396844303bab39d;p=gcc.git Add st[pr]ncpy to stmt_kills_ref_p 2017-04-29 Marc Glisse 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a2082928881..3e3474701d5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-04-29 Marc Glisse + + PR tree-optimization/80487 + * tree-ssa-alias.c (stmt_kills_ref_p): Handle stpncpy and strncpy. + 2017-04-29 Prathamesh Kulkarni PR tree-optimization/79697 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 59f1a31bfd7..2d3d02b018c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-29 Marc Glisse + + PR tree-optimization/80487 + * gcc.dg/tree-ssa/strncpy-1.c: New file. + 2017-04-29 Prathamesh Kulkarni 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 index 00000000000..751eaeaf9fc --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/strncpy-1.c @@ -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" } } */ diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index 0dcb273e5c2..8cab159916a 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -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. */