Go to file
David Malcolm 7761dfbee1 Use char_span for return type of location_get_source_line
location_get_source_line returns a const char * that isn't 0-terminated,
writing back a length through an int * param.

This is error-prone, as all call-sites have to take into account the
lack of 0-termination, and respect the length of the buffer.

It's cleaner to bundle together this pointer+length state into a class,
so this patch does so, reusing the "char_span" class that I introduced
in r250187 (as part of the fix for PR c/81405).

The patch also adds assertions to all access to the char_span.

gcc/c-family/ChangeLog:
	* c-format.c (get_corrected_substring): Update for
	location_get_source_line returning a char_span.  Use a char_span
	when handling the prefix of the correction.
	* c-indentation.c (get_visual_column): Update for
	location_get_source_line returning a char_span.
	(get_first_nws_vis_column): Likewise.

gcc/ChangeLog:
	* diagnostic-show-locus.c (layout::layout): Update for
	location_get_source_line returning a char_span.
	(struct char_span): Move to input.h.
	(struct correction): Update for fields in char_span becoming
	private.
	(struct source_line): Update for location_get_source_line
	returning a char_span.
	(layout::print_line): Likewise.
	* edit-context.c (edited_file::print_content): Likewise.
	(edited_file::print_diff_hunk): Likewise.
	(edited_file::print_run_of_changed_lines): Likewise.
	(edited_file::get_num_lines): Likewise.
	(edited_line::edited_line): Likewise.
	* final.c (asm_show_source): Likewise.
	* input.c (location_get_source_line): Convert return type
	from const char * to char_span, losing the final "line_len"
	param.
	(dump_location_info): Update for the above.
	(get_substring_ranges_for_loc): Likewise.  Use a char_span
	when handling the literal within the line.
	(test_reading_source_line): Update for location_get_source_line
	returning a char_span.
	* input.h (class char_span): Move here from
	diagnostic-show-locus.c, converting from a struct to a class.
	Make data members private.
	(char_span::operator bool): New.
	(char_span::length): New.
	(char_span::get_buffer): New.
	(char_span::operator[]): New.
	(char_span::subspan): Make const.
	(char_span::xstrdup): New.
	(location_get_source_line): Convert return type from const char *
	to char_span, losing the final "line_size" param.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
	(test_show_locus): Update for location_get_source_line returning a
	char_span.  Use char_span for handling words in the
	"test_many_nested_locations" fix-it example.

From-SVN: r259768
2018-04-30 15:01:56 +00:00
config x86/CET: Add -fcf-protection to STAGE4_CFLAGS 2018-04-24 15:12:46 -07:00
contrib
fixincludes
gcc Use char_span for return type of location_get_source_line 2018-04-30 15:01:56 +00:00
gnattools
gotools
include
INSTALL
intl
libada
libatomic Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
libbacktrace Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
libcc1
libcpp
libdecnumber
libffi
libgcc re PR libgcc/84292 (__sync_add_and_fetch returns the old value instead of the new value) 2018-04-27 21:14:05 +02:00
libgfortran Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
libgo re PR go/85429 (Several gotools tests FAIL with Solaris as) 2018-04-27 18:01:00 +00:00
libgomp [openacc, testsuite] Fix undefined behaviour in atomic_capture-1.c 2018-04-29 10:26:56 +00:00
libhsail-rt
libiberty
libitm x86: Update __CET__ check 2018-04-24 15:15:51 -07:00
libmpx Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
libobjc Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
liboffloadmic
libquadmath Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
libsanitizer If someone has access to a 64-bit mips-linux system to test this (with the obvious edit), that'd be really nice. 2018-04-26 01:16:47 +00:00
libssp Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
libstdc++-v3 Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
libvtv Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
lto-plugin
maintainer-scripts * crontab: Enable snapshots from gcc-8-branch. 2018-04-25 09:46:31 +02:00
zlib
.dir-locals.el
.gitattributes
.gitignore
ABOUT-NLS
ChangeLog re PR bootstrap/85571 (non-bootstrap-debug miscompare with trunk) 2018-04-30 08:18:03 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub
configure
configure.ac
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS MAINTAINERS (mips): Remove myself as MIPS maintainer. 2018-04-25 18:40:04 -04:00
Makefile.def
Makefile.in re PR bootstrap/85571 (non-bootstrap-debug miscompare with trunk) 2018-04-30 08:18:03 +00:00
Makefile.tpl re PR bootstrap/85571 (non-bootstrap-debug miscompare with trunk) 2018-04-30 08:18:03 +00:00
missing
mkdep
mkinstalldirs
move-if-change
README
symlink-tree
ylwrap

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.