gcc/libcpp
David Malcolm 5ccf1d8d10 Fix linemap corruption after very wide source lines (PR c++/72803)
PR c++/72803 describes an issue where a fix-it hint is to be emitted at
column 512 of a 511-column source line, leading to an ICE.

The root cause is a bug in linemap_line_start, when transitioning from
lines >= 512 in width to narrow lines.

The wide line in the reproducer has a line map with:
  m_column_and_range_bits = 15, m_range_bits = 5
giving 10 effective bits for representing columns, so that columns <= 1023
can be represented.

When parsing the following line,
  linemap_line_start (..., ..., max_column_hint=0);
is called.  This leads to the "add_map" logic, due to this condition:
      || (max_column_hint <= 80 && effective_column_bits >= 10)
i.e. the new line is sufficiently narrower than the old one to
potentially use a new linemap (so as to conserve values within the
location_t space).

It then attempts to avoid allocating a new line map.  Part of the logic
to determine if we really need a new line map is this condition:
   SOURCE_COLUMN (map, highest) >= (1U << column_bits)
The above condition is incorrect: we need to determine if the highest
column we've handed out will fit within the proposed *effective* column
bits, but "column_bits" here is the column plus the range bits, rather
than just the column bits.

Hence in this case linemap_line_start erroneously decides that we don't
need a new line map, and updates the column bits within the existing
line map, so any location_t values we've already handed out within it
that are offset from the start by
  >= (1<<new_column_and_range_bits)
effectively change meaning, leading to incorrect line&column information
when decoding them, and various "interesting" ways for the linemap
code to fail.

The fix is to use the effective column bits in the above conditional.

gcc/ChangeLog:
	PR c++/72803
	* input.c (selftest::test_accessing_ordinary_linemaps): Verify
	that the transition from a max line width >= 1<<10 to narrower
	lines works correctly.

gcc/testsuite/ChangeLog:
	PR c++/72803
	* g++.dg/diagnostic/pr72803.C: New test case.

libcpp/ChangeLog:
	PR c++/72803
	* line-map.c (linemap_line_start): When determining if the highest
	column given out so far will fit into a proposed change to the
	current map, use the effective number of column bits, rather than
	the total number of column + range bits.

From-SVN: r244199
2017-01-07 21:33:59 +00:00
..
include Update copyright years. 2017-01-01 13:07:43 +01:00
po * pt_BR.po, ru.po: Update. 2017-01-05 00:04:28 +00:00
ChangeLog Fix linemap corruption after very wide source lines (PR c++/72803) 2017-01-07 21:33:59 +00:00
ChangeLog.jit Merger of dmalcolm/jit branch from git 2014-11-11 21:55:52 +00:00
Makefile.in Update copyright years. 2017-01-01 13:07:43 +01:00
aclocal.m4 libcpp: Bump to automake 1.11.6 2015-05-13 11:02:17 +00:00
charset.c Update copyright years. 2017-01-01 13:07:43 +01:00
config.in re PR bootstrap/72823 (r239175 causes build failure) 2016-11-16 21:10:27 +01:00
configure re PR bootstrap/72823 (r239175 causes build failure) 2016-11-16 21:10:27 +01:00
configure.ac re PR bootstrap/72823 (r239175 causes build failure) 2016-11-16 21:10:27 +01:00
directives-only.c Update copyright years. 2017-01-01 13:07:43 +01:00
directives.c Update copyright years. 2017-01-01 13:07:43 +01:00
errors.c Update copyright years. 2017-01-01 13:07:43 +01:00
expr.c Update copyright years. 2017-01-01 13:07:43 +01:00
files.c Update copyright years. 2017-01-01 13:07:43 +01:00
identifiers.c Update copyright years. 2017-01-01 13:07:43 +01:00
init.c Update copyright years. 2017-01-01 13:07:43 +01:00
internal.h Update copyright years. 2017-01-01 13:07:43 +01:00
lex.c Update copyright years. 2017-01-01 13:07:43 +01:00
line-map.c Fix linemap corruption after very wide source lines (PR c++/72803) 2017-01-07 21:33:59 +00:00
location-example.txt Source range tracking in libcpp and C FE, with bit-packing optimization 2015-11-13 16:29:59 +00:00
macro.c Update copyright years. 2017-01-01 13:07:43 +01:00
makeucnid.c Update copyright years. 2017-01-01 13:07:43 +01:00
mkdeps.c Update copyright years. 2017-01-01 13:07:43 +01:00
pch.c Update copyright years. 2017-01-01 13:07:43 +01:00
symtab.c Update copyright years. 2017-01-01 13:07:43 +01:00
system.h Update copyright years. 2017-01-01 13:07:43 +01:00
traditional.c Update copyright years. 2017-01-01 13:07:43 +01:00
ucnid.h Update copyright years. 2017-01-01 13:07:43 +01:00
ucnid.tab Update copyright years. 2017-01-01 13:07:43 +01:00