gcc/libcpp
David Malcolm 200a8e1a38 Fix ICE with #line directive (PR c/89410)
PR c/89410 reports various issues with #line directives with very
large numbers; one of them is an ICE inside diagnostic-show-locus.c
when emitting a diagnostic at line 0xffffffff.

The issue is that the arithmetic in layout::calculate_line_spans to
determine if two line spans are sufficiently close to consolidate
was using the unsigned 32-bit linenum_type, which was overflowing
when comparing the line for the expanded location with those of
the location range (all on line 0xffffffff), leading to it
erroneously adding two spans for the same line, leading to an
assertion failure.

This patch fixes the ICE by generalizing the use of long long in
line-map.h's comparison function for linenum_type into a new
linenum_arith_t typedef, and using it here.

Doing so uncovered a second problem: the loop to print the lines
within the line_span for this case is infinite: looping from
0xfffffff upwards, overflowing to 0, and then never becoming
greater than 0xfffffff.  The patch fixes this by using linenum_arith_t
there also.

gcc/ChangeLog:
	PR c/89410
	* diagnostic-show-locus.c (layout::calculate_line_spans): Use
	linenum_arith_t when determining if two adjacent line spans are
	close enough to merge.
	(diagnostic_show_locus): Use linenum_arith_t when iterating over
	lines within each line_span.

gcc/testsuite/ChangeLog:
	PR c/89410
	* gcc.dg/pr89410-1.c: New test.
	* gcc.dg/pr89410-2.c: New test.

libcpp/ChangeLog:
	PR c/89410
	* include/line-map.h (linenum_arith_t): New typedef.
	(compare): Use it.

From-SVN: r269050
2019-02-20 20:07:20 +00:00
..
include Fix ICE with #line directive (PR c/89410) 2019-02-20 20:07:20 +00:00
po * da.po: Update. 2019-02-14 20:50:51 +00:00
ChangeLog Fix ICE with #line directive (PR c/89410) 2019-02-20 20:07:20 +00:00
ChangeLog.jit
Makefile.in Update copyright years. 2019-01-01 13:31:55 +01:00
aclocal.m4 Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
charset.c Update copyright years. 2019-01-01 13:31:55 +01:00
config.in Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
configure iconv.m4 (AM_ICONV_LINK): Don't overwrite CPPFLAGS. 2018-11-07 15:41:21 -07:00
configure.ac Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
directives-only.c Update copyright years. 2019-01-01 13:31:55 +01:00
directives.c re PR preprocessor/88974 (ICE: Segmentation fault (in linemap_resolve_location)) 2019-01-26 11:08:00 +01:00
errors.c Update copyright years. 2019-01-01 13:31:55 +01:00
expr.c re PR preprocessor/88974 (ICE: Segmentation fault (in linemap_resolve_location)) 2019-01-26 11:08:00 +01:00
files.c Update copyright years. 2019-01-01 13:31:55 +01:00
identifiers.c Update copyright years. 2019-01-01 13:31:55 +01:00
init.c Update copyright years. 2019-01-01 13:31:55 +01:00
internal.h re PR preprocessor/88974 (ICE: Segmentation fault (in linemap_resolve_location)) 2019-01-26 11:08:00 +01:00
lex.c Update copyright years. 2019-01-01 13:31:55 +01:00
line-map.c Use 1UL constant in order to not overflow (PR c++/89383). 2019-02-18 09:46:19 +00:00
location-example.txt PR preprocessor/83173: Enhance -fdump-internal-locations output 2018-11-27 16:04:31 +00:00
macro.c Update copyright years. 2019-01-01 13:31:55 +01:00
makeucnid.c Update copyright years. 2019-01-01 13:31:55 +01:00
mkdeps.c Update copyright years. 2019-01-01 13:31:55 +01:00
pch.c Update copyright years. 2019-01-01 13:31:55 +01:00
symtab.c Update copyright years. 2019-01-01 13:31:55 +01:00
system.h Update copyright years. 2019-01-01 13:31:55 +01:00
traditional.c Update copyright years. 2019-01-01 13:31:55 +01:00
ucnid.h Update copyright years. 2019-01-01 13:31:55 +01:00
ucnid.tab Update copyright years. 2019-01-01 13:31:55 +01:00