Fix ICE in get_substring_ranges_for_loc on __FILE__ (PR c++/87721)
commit99069acda53cf775cdf5e5b81a4f4104e16f3835
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Oct 2018 23:58:34 +0000 (29 23:58 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Oct 2018 23:58:34 +0000 (29 23:58 +0000)
treefe13868d9238eb20dea3293cffca6f47e0d55a92
parentd42760aad21210643e00f090bdb52a93066e18a7
Fix ICE in get_substring_ranges_for_loc on __FILE__ (PR c++/87721)

PR c++/87721 reports a crash in get_substring_ranges_for_loc introduced
by r265271, my fix for PR 87562.

The new issue occurs when attempting to get a location with a string
literal inside a macro in which the first token is __FILE__ (formed via
concatenation).  Attempting to get the spelling location of __FILE__
fails, leading to NULL for start_ord_map and final_ord_map, and thus
a NULL pointer dereference.

Given that our "on-demand" substring locations approach reparses the
string literals, there isn't a good way to access the locations inside
such string literals: attempting to reparse __FILE__ fails with a
"missing open quote".

This patch applies the easy fix by gracefully rejecting the case where
the spelling locations for the start or finish give us NULL maps.

gcc/ChangeLog:
PR c++/87721
* input.c (get_substring_ranges_for_loc): Detect if
linemap_resolve_location gives us a NULL map, and reject
this case.

gcc/testsuite/ChangeLog:
PR c++/87721
* c-c++-common/substring-location-PR-87721.c: New test.
* gcc.dg/plugin/diagnostic-test-string-literals-1.c: Add test for
PR 87721.
* gcc.dg/plugin/diagnostic_plugin_test_string_literals.c
(test_string_literals): Fold the index arguments before checking
for INTEGER_CST.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@265611 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/input.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/substring-location-PR-87721.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c
gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c