[Bug c/82050] [8 Regression] ICE on invalid code on x86_64-linux-gnu in column_range, at diagnostic-show-locus.c:1403

2017-12-11 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82050

--- Comment #9 from David Malcolm  ---
Author: dmalcolm
Date: Tue Dec 12 01:31:30 2017
New Revision: 255563

URL: https://gcc.gnu.org/viewcvs?rev=255563=gcc=rev
Log:
Expensive selftests: torture testing for fix-it boundary conditions (PR
c/82050)

This patch adds selftest coverage for the fix for PR c/82050.

The selftest iterates over various "interesting" column and line-width
values to try to shake out bugs in the fix-it printing routines, a kind
of "torture" selftest.

Unfortunately this selftest is noticably slower than the other selftests;
adding it to diagnostic-show-locus.c led to:
  -fself-test: 40218 pass(es) in 0.172000 seconds
slowing down to:
  -fself-test: 97315 pass(es) in 6.109000 seconds
for an unoptimized build (e.g. when hacking with --disable-bootstrap).

Given that this affects the compile-edit-test cycle of the "gcc"
subdirectory, this felt like an unacceptable amount of overhead to add.

I attempted to optimize the test by reducing the amount of coverage, but
the test seems useful, and there seems to be a valid role for "torture"
selftests.

Hence this patch adds a:
  gcc.dg/plugin/expensive_selftests_plugin.c
with the responsibility for running "expensive" selftests, and adds the
expensive test there.  The patch moves a small amount of code from
selftest::run_tests into a helper class so that the plugin can print
a useful summary line (to reassure us that the tests are actually being
run).

With that, the compile-edit-test cycle of the "gcc" subdir is unaffected;
the plugin takes:
  expensive_selftests_plugin: 26641 pass(es) in 3.127000 seconds
which seems reasonable within the much longer time taken by "make check"
(I optimized some of the overhead away, hence the reduction from 6 seconds
above down to 3 seconds).

gcc/ChangeLog:
PR c/82050
* selftest-run-tests.c (selftest::run_tests): Move start/finish code
to...
* selftest.c (selftest::test_runner::test_runner): New ctor.
(selftest::test_runner::~test_runner): New dtor.
* selftest.h (class selftest::test_runner): New class.

gcc/testsuite/ChangeLog:
PR c/82050
* gcc.dg/plugin/expensive-selftests-1.c: New file.
* gcc.dg/plugin/expensive_selftests_plugin.c: New file.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above.


Added:
trunk/gcc/testsuite/gcc.dg/plugin/expensive-selftests-1.c
trunk/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/selftest-run-tests.c
trunk/gcc/selftest.c
trunk/gcc/selftest.h
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.dg/plugin/plugin.exp

[Bug c/82050] [8 Regression] ICE on invalid code on x86_64-linux-gnu in column_range, at diagnostic-show-locus.c:1403

2017-11-28 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82050

--- Comment #8 from David Malcolm  ---
Author: dmalcolm
Date: Tue Nov 28 21:45:56 2017
New Revision: 255219

URL: https://gcc.gnu.org/viewcvs?rev=255219=gcc=rev
Log:
Handle very long lines when printing fix-it hints

When fixing PR c/82050 I noticed a bug in how we print fix-it hints
for very long lines: we weren't taking into account the x-offset for
the line when printing the fix-it hint.

This could lead to output where instead of printing:

foo.c:14:3944: error: etc
  = foo.field
^
replacement

where the lines have been offset to start printing at about column 3900,
the "replacement" line was erroneously *not* offset, and was thus
prefixed by thousands of spaces, leading to large whitespace gaps in
the output, and the replacement failing to line up with the source to be
replaced.

Fixed thusly.

gcc/ChangeLog:
* diagnostic-show-locus.c (layout::print_trailing_fixits): Handle
m_x_offset.
(layout::move_to_column): Likewise.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-show-locus-bw.c
(test_very_wide_line): Update expected output to include a
fix-it hint.
* gcc.dg/plugin/diagnostic-test-show-locus-color.c
(test_very_wide_line): Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(test_show_locus): Add a fix-it hint to "test_very_wide_line".


Modified:
trunk/gcc/ChangeLog
trunk/gcc/diagnostic-show-locus.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c
trunk/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c
trunk/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c

[Bug c/82050] [8 Regression] ICE on invalid code on x86_64-linux-gnu in column_range, at diagnostic-show-locus.c:1403

2017-11-28 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82050

David Malcolm  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #7 from David Malcolm  ---
Fixed on trunk for gcc 8 by r255214.

Candidate followup patch for test coverage:
  https://gcc.gnu.org/ml/gcc-patches/2017-11/msg02459.html

[Bug c/82050] [8 Regression] ICE on invalid code on x86_64-linux-gnu in column_range, at diagnostic-show-locus.c:1403

2017-11-28 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82050

--- Comment #6 from David Malcolm  ---
Author: dmalcolm
Date: Tue Nov 28 19:24:35 2017
New Revision: 255214

URL: https://gcc.gnu.org/viewcvs?rev=255214=gcc=rev
Log:
Reject fix-it hints for various awkward boundary cases (PR c/82050)

PR c/82050 reports a failed assertion deep within diagnostic_show_locus's
code for printing fix-it hints.

The root cause is a fix-it hint suggesting a textual replacement,
where the affected column numbers straddle the LINE_MAP_MAX_COLUMN_NUMBER
boundary, so that the start of the range has a column number, but the
end of the range doesn't.

The fix is to verify that the column numbers are sane when adding fix-it
hints to a rich_location, rejecting fix-it hints where they are not.

libcpp/ChangeLog:
PR c/82050
* include/line-map.h (LINE_MAP_MAX_COLUMN_NUMBER): Move here.
* line-map.c (LINE_MAP_MAX_COLUMN_NUMBER): ...from here.
(rich_location::maybe_add_fixit): Reject fix-it hints in which
the start column exceeds the next column.


Modified:
trunk/libcpp/ChangeLog
trunk/libcpp/include/line-map.h
trunk/libcpp/line-map.c

[Bug c/82050] [8 Regression] ICE on invalid code on x86_64-linux-gnu in column_range, at diagnostic-show-locus.c:1403

2017-11-23 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82050

David Malcolm  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |dmalcolm at gcc dot 
gnu.org

--- Comment #5 from David Malcolm  ---
Thanks!

[Bug c/82050] [8 Regression] ICE on invalid code on x86_64-linux-gnu in column_range, at diagnostic-show-locus.c:1403

2017-11-23 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82050

--- Comment #4 from Jakub Jelinek  ---
Created attachment 42697
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42697=edit
pr82050.c

Here it is.

[Bug c/82050] [8 Regression] ICE on invalid code on x86_64-linux-gnu in column_range, at diagnostic-show-locus.c:1403

2017-11-23 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82050

--- Comment #3 from David Malcolm  ---
I attempted to copy from comment #0, but couldn't reproduce the ICE
(possibly a spaces vs tabs thing?)

Jakub: please can you attach the reproducer file, and I'll take this.  Thanks.

[Bug c/82050] [8 Regression] ICE on invalid code on x86_64-linux-gnu in column_range, at diagnostic-show-locus.c:1403

2017-11-23 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82050

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek  ---
In:
1418static column_range
1419get_affected_columns (const fixit_hint *hint)
1420{
1421  int start_column = LOCATION_COLUMN (hint->get_start_loc ());
1422  int finish_column = LOCATION_COLUMN (hint->get_next_loc ()) - 1;
1423
1424  return column_range (start_column, finish_column);
(gdb) p hint->get_start_loc ()
$3 = 438112
(gdb) p hint->get_next_loc ()
$4 = 307392
(gdb) p expand_location ($3)
$5 = {file = 0x7fffe3d1 "pr82050.c", line = 14, column = 4086, data = 0x0,
sysp = false}
(gdb) p expand_location ($4)
$6 = {file = 0x7fffe3d1 "pr82050.c", line = 14, column = 1, data = 0x0,
sysp = false}

so finish_column is 0 and smaller than start_column, which is what column_range
ICEs on.  Is that because we have:
/* Do not track column numbers higher than this one.  As a result, the
   range of column_bits is [12, 18] (or 0 if column numbers are
   disabled).  */
const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 12);
and thus effectively can only track columns up to 4095 (or 4096 if 1 based)?
If so, something should punt on it rather than ICE it is not possible.

[Bug c/82050] [8 Regression] ICE on invalid code on x86_64-linux-gnu in column_range, at diagnostic-show-locus.c:1403

2017-08-31 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82050

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|--- |8.0

[Bug c/82050] [8 Regression] ICE on invalid code on x86_64-linux-gnu in column_range, at diagnostic-show-locus.c:1403

2017-08-31 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82050

Martin Liška  changed:

   What|Removed |Added

   Keywords||ice-on-valid-code
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-08-31
 CC||dmalcolm at gcc dot gnu.org,
   ||marxin at gcc dot gnu.org
Summary|ICE on invalid code on  |[8 Regression] ICE on
   |x86_64-linux-gnu in |invalid code on
   |column_range, at|x86_64-linux-gnu in
   |diagnostic-show-locus.c:140 |column_range, at
   |3   |diagnostic-show-locus.c:140
   ||3
 Ever confirmed|0   |1
  Known to fail||8.0

--- Comment #1 from Martin Liška  ---
Started with r250187.