e3f9a279f5
tree-ssa-strlen.c looks for cases in which a string is built up using operations like: memcpy (a, "foo", 4); memcpy (a + 3, "bar", 4); int x = strlen (a); As a side-effect, it optimises the non-final memcpys so that they don't include the nul terminator. However, after removing some "& ~0x1"s from tree-ssa-dse.c, the DSE pass does this optimisation itself (because it can tell that later memcpys overwrite the terminators). The strlen pass wasn't able to handle these pre-optimised calls in the same way as the unoptimised ones. This patch adds support for tracking unterminated strings. [Based on the code ARM contributed in branches/ARM/sve-branch@246236] 2017-07-02 Richard Sandiford <richard.sandiford@linaro.org> gcc/ * tree-ssa-strlen.c (strinfo): Rename the length field to nonzero_chars. Add a full_string_p field. (compare_nonzero_chars, zero_length_string_p): New functions. (get_addr_stridx): Add an offset_out parameter. Use compare_nonzero_chars. (get_stridx): Update accordingly. Use compare_nonzero_chars. (new_strinfo): Update after above changes to strinfo. (set_endptr_and_length): Set full_string_p. (get_string_length): Update after above changes to strinfo. (unshare_strinfo): Update call to new_strinfo. (maybe_invalidate): Likewise. (get_stridx_plus_constant): Change off to unsigned HOST_WIDE_INT. Use compare_nonzero_chars and zero_string_p. Treat nonzero_chars as a uhwi instead of an shwi. Update after above changes to strinfo and new_strinfo. (zero_length_string): Assert that chainsi contains full strings. Use zero_length_string_p. Update call to new_strinfo. (adjust_related_strinfos): Update after above changes to strinfo. Copy full_string_p from origsi. (adjust_last_stmt): Use zero_length_string_p. (handle_builtin_strlen): Update after above changes to strinfo and new_strinfo. Install the lhs as the string length if the previous entry didn't describe a full string. (handle_builtin_strchr): Update after above changes to strinfo and new_strinfo. (handle_builtin_strcpy): Likewise. (handle_builtin_strcat): Likewise. (handle_builtin_malloc): Likewise. (handle_pointer_plus): Likewise. (handle_builtin_memcpy): Likewise. Track nonzero characters that aren't necessarily followed by a nul terminator. (handle_char_store): Likewise. gcc/testsuite/ * gcc.dg/strlenopt-32.c: New testcase. * gcc.dg/strlenopt-33.c: Likewise. * gcc.dg/strlenopt-33g.c: Likewise. * gcc.dg/strlenopt-34.c: Likewise. * gcc.dg/strlenopt-35.c: Likewise. From-SVN: r249880 |
||
---|---|---|
INSTALL | ||
config | ||
contrib | ||
fixincludes | ||
gcc | ||
gnattools | ||
gotools | ||
include | ||
intl | ||
libada | ||
libatomic | ||
libbacktrace | ||
libcc1 | ||
libcilkrts | ||
libcpp | ||
libdecnumber | ||
libffi | ||
libgcc | ||
libgfortran | ||
libgo | ||
libgomp | ||
libhsail-rt | ||
libiberty | ||
libitm | ||
libmpx | ||
libobjc | ||
liboffloadmic | ||
libquadmath | ||
libsanitizer | ||
libssp | ||
libstdc++-v3 | ||
libvtv | ||
lto-plugin | ||
maintainer-scripts | ||
zlib | ||
.dir-locals.el | ||
.gitattributes | ||
.gitignore | ||
ABOUT-NLS | ||
COPYING | ||
COPYING.LIB | ||
COPYING.RUNTIME | ||
COPYING3 | ||
COPYING3.LIB | ||
ChangeLog | ||
ChangeLog.jit | ||
ChangeLog.tree-ssa | ||
MAINTAINERS | ||
Makefile.def | ||
Makefile.in | ||
Makefile.tpl | ||
README | ||
compile | ||
config-ml.in | ||
config.guess | ||
config.rpath | ||
config.sub | ||
configure | ||
configure.ac | ||
depcomp | ||
install-sh | ||
libtool-ldflags | ||
libtool.m4 | ||
ltgcc.m4 | ||
ltmain.sh | ||
ltoptions.m4 | ||
ltsugar.m4 | ||
ltversion.m4 | ||
lt~obsolete.m4 | ||
missing | ||
mkdep | ||
mkinstalldirs | ||
move-if-change | ||
symlink-tree | ||
ylwrap |
README
This directory contains the GNU Compiler Collection (GCC). The GNU Compiler Collection is free software. See the files whose names start with COPYING for copying permission. The manuals, and some of the runtime libraries, are under different terms; see the individual source files for details. The directory INSTALL contains copies of the installation information as HTML and plain text. The source of this information is gcc/doc/install.texi. The installation information includes details of what is included in the GCC sources and what files GCC installs. See the file gcc/doc/gcc.texi (together with other files that it includes) for usage and porting information. An online readable version of the manual is in the files gcc/doc/gcc.info*. See http://gcc.gnu.org/bugs/ for how to report bugs usefully. Copyright years on GCC source files may be listed using range notation, e.g., 1987-2012, indicating that every year in the range, inclusive, is a copyrightable year that could otherwise be listed individually.