Find a file
David Malcolm 338d6484d1 diagnostics: fix crash when consolidating out-of-order fix-it hints (PR c/81405)
PR c/81405 identifies a crash when printing fix-it hints from
-Wmissing-braces when there are excess elements.

The fix-it hints are bogus (which I've filed separately as PR c/81432),
but they lead to a crash within the fix-it consolidation logic I added
in r247548, in line_corrections::add_hint.

The root cause is that some of the fix-it hints are out-of-order
with respect to the column numbers they affect, which can lead to negative
values when computing the gap between the fix-it hints, leading to bogus
memcpy calls that generate out-of-bounds buffer accesses.

The fix is to sort the fix-it hints after filtering them, ensuring that
the gap >= 0.  The patch also adds numerous assertions to the code, both
directly, and by moving the memcpy calls and their args behind
interfaces (themselves containing gcc_assert).

This fixes the crash; it doesn't fix the bug in -Wmissing-braces that
leads to the bogus hints.

gcc/ChangeLog:
	PR c/81405
	* diagnostic-show-locus.c (fixit_cmp): New function.
	(layout::layout): Sort m_fixit_hints.
	(column_range::column_range): Assert that the values are valid.
	(struct char_span): New struct.
	(correction::overwrite): New method.
	(struct source_line): New struct.
	(line_corrections::add_hint): Add assertions.  Reimplement memcpy
	calls in terms of classes source_line and char_span, and
	correction::overwrite.
	(selftest::test_overlapped_fixit_printing_2): New function.
	(selftest::diagnostic_show_locus_c_tests): Call it.

gcc/testsuite/ChangeLog:
	PR c/81405
	* gcc.dg/Wmissing-braces-fixits.c: Add coverage for PR c/81405.  */

From-SVN: r250187
2017-07-13 19:30:42 +00:00
config Enable -flto in all PGO stages for bootstrap-lto-{,noplugin}.mk. 2017-06-19 13:20:20 +00:00
contrib [arm] Move some generated files out of the source tree 2017-07-04 14:49:38 +00:00
fixincludes config.gcc (*-*-vxworks*): Set use_gcc_stdint to "provide". 2017-06-12 12:10:12 +00:00
gcc diagnostics: fix crash when consolidating out-of-order fix-it hints (PR c/81405) 2017-07-13 19:30: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 include/ChangeLog 2017-07-02 20:00:48 +00:00
INSTALL
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 revert previous premature commit 2017-07-13 12:38:32 +00:00
libcilkrts os-unix-sysdep.c (__cilkrts_getticks): Adjust preprocessor test for SPARC/Linux. 2017-06-23 17:33:43 +00:00
libcpp libcpp: preserve ranges within macro expansions (PR c++/79300) 2017-07-07 18:49:09 +00: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 re PR target/81193 (PowerPC GCC __builtin_cpu_is and __builtin_cpu_supports should warn about old libraries) 2017-07-12 23:07:50 +00:00
libgfortran eoshift2.c (eoshift2): Use memcpy for innermost copy where possible. 2017-07-09 19:09:33 +00:00
libgo re PR go/81393 (Bootstrap failure on s390x-linux while building libgo against recent glibc) 2017-07-13 03:44:14 +00:00
libgomp Fix secure_getenv.h include in plugin-hsa.c 2017-07-03 13:40:19 +00:00
libhsail-rt Minor BRIG/HSAIL frontend updates and bug fixes: 2017-05-04 05:50:21 +00:00
libiberty include/ChangeLog 2017-07-02 20:00:48 +00: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 Improvements to the libstdc++ FAQ and manual 2017-07-11 12:11:33 +01: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
ChangeLog [arm] Move some generated files out of the source tree 2017-07-04 14:49:38 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
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: Set srcdir when sourcing config-lang.in fragments. 2017-07-03 14:16:59 +00:00
configure.ac configure.ac: Set srcdir when sourcing config-lang.in fragments. 2017-07-03 14:16:59 +00:00
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
depcomp
install-sh
libtool-ldflags
libtool.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS Readd myself as c6x maintainer. 2017-07-03 14:01:00 +00: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
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.