diff options
author | Martin Sebor <msebor@redhat.com> | 2017-12-06 17:47:45 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2017-12-06 10:47:45 -0700 |
commit | 25b15e953ac48e5042e27a4419ca20211403b7cb (patch) | |
tree | 8702db003aa73c7b1a8670612c78ec7cd47578ea /gcc/tree-ssa-strlen.c | |
parent | 4c413747a31d0dd8ecfc05312584725d2f0955f6 (diff) | |
download | gcc-25b15e953ac48e5042e27a4419ca20211403b7cb.zip gcc-25b15e953ac48e5042e27a4419ca20211403b7cb.tar.gz gcc-25b15e953ac48e5042e27a4419ca20211403b7cb.tar.bz2 |
PR tree-optimization/83075 - Invalid strncpy optimization
gcc/ChangeLog:
PR tree-optimization/83075
* tree-ssa-strlen.c (handle_builtin_stxncpy): Avoid assuming
strncat/strncpy don't change length of source string.
gcc/testsuite/ChangeLog:
PR tree-optimization/83075
* gcc.dg/tree-ssa/strncat.c: New test.
* gcc.dg/tree-ssa/strncpy-2.c: Same.
From-SVN: r255446
Diffstat (limited to 'gcc/tree-ssa-strlen.c')
-rw-r--r-- | gcc/tree-ssa-strlen.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 48b9241..94f20ef 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -1941,10 +1941,9 @@ handle_builtin_stxncpy (built_in_function, gimple_stmt_iterator *gsi) int sidx = get_stridx (src); strinfo *sisrc = sidx > 0 ? get_strinfo (sidx) : NULL; - /* Strncpy() et al. cannot modify the source string. Prevent the rest - of the pass from invalidating the strinfo data. */ - if (sisrc) - sisrc->dont_invalidate = true; + /* strncat() and strncpy() can modify the source string by writing + over the terminating nul so SISRC->DONT_INVALIDATE must be left + clear. */ /* Retrieve the strinfo data for the string S that LEN was computed from as some function F of strlen (S) (i.e., LEN need not be equal |