Go to file
Richard Sandiford e3f9a279f5 Make tree-ssa-strlen.c handle partial unterminated strings
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
2017-07-02 08:52:42 +00:00
INSTALL README: Do not mention CVS. 2014-10-12 15:05:28 +00:00
config Enable -flto in all PGO stages for bootstrap-lto-{,noplugin}.mk. 2017-06-19 13:20:20 +00:00
contrib Doxygen: add default location for filters and output folder. 2017-06-28 07:52:46 +00:00
fixincludes config.gcc (*-*-vxworks*): Set use_gcc_stdint to "provide". 2017-06-12 12:10:12 +00:00
gcc Make tree-ssa-strlen.c handle partial unterminated strings 2017-07-02 08:52:42 +00:00
gnattools configure.ac: Add ACX_NONCANONICAL_HOST. 2016-05-16 08:55:12 +00:00
gotools Makefile.am (MOSTLYCLEANFILES): Remove testing files and logs. 2017-06-29 16:01:38 +00:00
include * longlong.h: Remove ns32k support. 2017-06-27 10:10:15 -06:00
intl config-ml.in: Remove references to GCJ. 2016-11-15 16:34:02 +00:00
libada re PR ada/80921 (cross compiling fails to build Ada shared libraries) 2017-06-01 10:51:15 +00:00
libatomic Load new scanlang.exp 2017-05-12 09:20:37 +00:00
libbacktrace configure.ac: Add AC_SYS_LARGEFILE. 2017-06-21 07:04:13 +00:00
libcc1 config-lang.in (gtfiles): Add cp/lex.c. 2017-06-30 18:46:01 +00:00
libcilkrts os-unix-sysdep.c (__cilkrts_getticks): Adjust preprocessor test for SPARC/Linux. 2017-06-23 17:33:43 +00:00
libcpp line-map.c (location_adhoc_data_update): Perform addition in uintptr_t type rather than char * type. 2017-06-21 12:59:12 +02:00
libdecnumber bid2dpd_dpd2bid.c (_bid_to_dpd32): Fix whitespace. 2017-06-29 11:35:03 -06:00
libffi re PR other/79046 (g++ -print-file-name=plugin uses full version number in path) 2017-01-21 09:47:11 +01:00
libgcc Use ucontext_t not struct ucontext in linux-unwind.h files. 2017-06-28 10:21:16 +01:00
libgfortran Fix for SPEC CPU2017 621.wrf_s failure, add missing locking code. 2017-06-26 14:40:47 -07:00
libgo misc/cgo/testcarchive: fix test to work for gccgo 2017-06-29 15:17:20 +00:00
libgomp Show value of GOMP_OPENACC_DIM in libgomp nvptx plugin 2017-06-27 15:51:48 +00:00
libhsail-rt Minor BRIG/HSAIL frontend updates and bug fixes: 2017-05-04 05:50:21 +00:00
libiberty simple-object-xcoff.c (simple_object_xcoff_find_sections): Search symbol table for .go_export symbol and apply pfn if found. 2017-06-07 19:23:55 -04:00
libitm PR c++/80560 - warn on undefined memory operations involving non-trivial types 2017-06-15 21:48:59 -06:00
libmpx * mpxrt/mpxrt-utils.h (__mpxrt_stop): New prototype. 2017-01-30 15:26:24 +01:00
libobjc re PR tree-optimization/79256 (FAIL: gcc.dg/vect/pr25413a.c execution test) 2017-02-07 11:29:06 +00:00
liboffloadmic libgomp: Provide prototypes for functions implemented by libgomp plugins 2017-01-31 15:32:58 +01:00
libquadmath configure.ac (ACX_BUGURL): Update. 2017-02-09 10:56:08 +00:00
libsanitizer Cherry-pick upstream r299036 from libsanitizer (PR sanitizer/80166). 2017-04-06 13:42:24 +00:00
libssp ssp.c (__guard_setup): Suppress unused variable warning. 2017-04-02 00:35:58 +00:00
libstdc++-v3 re PR libstdc++/80187 (C++ variant should be trivially copy constructible if possible) 2017-06-27 18:19:03 +00:00
libvtv re PR other/79046 (g++ -print-file-name=plugin uses full version number in path) 2017-01-21 09:47:11 +01:00
lto-plugin re PR other/79046 (g++ -print-file-name=plugin uses full version number in path) 2017-01-17 10:38:48 +01:00
maintainer-scripts gcc_release (XZ): Default to xz --best. 2017-05-23 23:14:10 +00:00
zlib re PR bootstrap/79771 (in-tree zlib breaks build) 2017-03-14 23:01:23 -06:00
.dir-locals.el
.gitattributes add basic .gitattributes files to notice whitespace issues 2016-04-23 02:37:43 +00:00
.gitignore .gitignore: Ignore in-tree prerequisites. 2016-09-09 17:20:55 -04:00
ABOUT-NLS
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
ChangeLog re PR bootstrap/81217 (Makefile:22754: warning: overriding recipe for target 'profiledbootstrap') 2017-06-28 07:54:14 +00:00
ChangeLog.jit Merger of dmalcolm/jit branch from git 2014-11-11 21:55:52 +00:00
ChangeLog.tree-ssa
MAINTAINERS * MAINTAINERS: Add myself to Write After Approval. 2017-06-26 12:44:49 +03:00
Makefile.def re PR bootstrap/81217 (Makefile:22754: warning: overriding recipe for target 'profiledbootstrap') 2017-06-28 07:54:14 +00:00
Makefile.in re PR bootstrap/81217 (Makefile:22754: warning: overriding recipe for target 'profiledbootstrap') 2017-06-28 07:54:14 +00:00
Makefile.tpl Introduce 4-stages profiledbootstrap to get a better profile. 2017-06-19 13:19:56 +00:00
README
compile Update from upstream Automake files. 2014-11-16 14:07:13 +00:00
config-ml.in config-ml.in: Remove references to GCJ. 2016-11-15 16:34:02 +00:00
config.guess * config.guess: Import latest from upstream. 2017-03-18 18:22:06 +00:00
config.rpath
config.sub * config.sub: Import latest version. 2016-12-29 22:04:53 +11:00
configure configure.ac (*-*-linux-android*): Set target_makefile_frag. 2017-06-03 08:23:22 +00:00
configure.ac configure.ac (*-*-linux-android*): Set target_makefile_frag. 2017-06-03 08:23:22 +00:00
depcomp Update from upstream Automake files. 2014-11-16 14:07:13 +00:00
install-sh Update from upstream Automake files. 2014-11-16 14:07:13 +00:00
libtool-ldflags
libtool.m4 * libtool.m4 (export_symbols_cmds) [AIX]: Add global TLS "L" symbols. 2015-11-26 08:20:59 -05:00
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
missing Update from upstream Automake files. 2014-11-16 14:07:13 +00:00
mkdep
mkinstalldirs Update from upstream Automake files. 2014-11-16 14:07:13 +00:00
move-if-change Update move-if-change from gnulib 2014-11-16 16:12:44 +00:00
symlink-tree
ylwrap Update from upstream Automake files. 2014-11-16 14:07:13 +00:00

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.