aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2017-06-20 10:40:38 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2017-06-20 10:40:38 +0000
commitc2403f36287ffd90629aa67b204f35844fc237fb (patch)
treefe86d10819506cdb8f17e6172d8ed766eb12c2fa /libcpp
parent199666f5a9eb29a00514ce8277c7b122e3297dd1 (diff)
Prevent fix-it hints from affecting more than one line
Attempts to apply a removal or replacement fix-it hint to a source range that covers multiple lines currently lead to nonsensical results from the printing code in diagnostic-show-locus.c. We were already filtering them out in edit-context.c (leading to -fdiagnostics-generate-patch not generating any output for the whole TU). Reject attempts to add such fix-it hints within rich_location, fixing the diagnostic-show-locus.c issue. gcc/ChangeLog: * diagnostic-show-locus.c (selftest::test_fixit_deletion_affecting_newline): New function. (selftest::diagnostic_show_locus_c_tests): Call it. libcpp/ChangeLog: * include/line-map.h (class rich_location): Document that attempts to delete or replace a range *affecting* multiple lines will fail. * line-map.c (rich_location::maybe_add_fixit): Implement this restriction. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@249403 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog7
-rw-r--r--libcpp/include/line-map.h2
-rw-r--r--libcpp/line-map.c21
3 files changed, 28 insertions, 2 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 13a33c302f6..9665f6e16c9 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+2017-06-20 David Malcolm <dmalcolm@redhat.com>
+
+ * include/line-map.h (class rich_location): Document that attempts
+ to delete or replace a range *affecting* multiple lines will fail.
+ * line-map.c (rich_location::maybe_add_fixit): Implement this
+ restriction.
+
2017-06-09 David Malcolm <dmalcolm@redhat.com>
* include/line-map.h
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index be3041df2be..f5c19e31a94 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -1556,6 +1556,8 @@ class fixit_hint;
inserting at the start of a line, and finishing with a newline
(with no interior newline characters). Other attempts to add
fix-it hints containing newline characters will fail.
+ Similarly, attempts to delete or replace a range *affecting* multiple
+ lines will fail.
The rich_location API handles these failures gracefully, so that
diagnostics can attempt to add fix-it hints without each needing
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 694137a7360..7ba003add98 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -2327,6 +2327,25 @@ rich_location::maybe_add_fixit (source_location start,
if (reject_impossible_fixit (next_loc))
return;
+ /* Only allow fix-it hints that affect a single line in one file.
+ Compare the end-points. */
+ expanded_location exploc_start
+ = linemap_client_expand_location_to_spelling_point (start);
+ expanded_location exploc_next_loc
+ = linemap_client_expand_location_to_spelling_point (next_loc);
+ /* They must be within the same file... */
+ if (exploc_start.file != exploc_next_loc.file)
+ {
+ stop_supporting_fixits ();
+ return;
+ }
+ /* ...and on the same line. */
+ if (exploc_start.line != exploc_next_loc.line)
+ {
+ stop_supporting_fixits ();
+ return;
+ }
+
const char *newline = strchr (new_content, '\n');
if (newline)
{
@@ -2342,8 +2361,6 @@ rich_location::maybe_add_fixit (source_location start,
}
/* The insertion must be at the start of a line. */
- expanded_location exploc_start
- = linemap_client_expand_location_to_spelling_point (start);
if (exploc_start.column != 1)
{
stop_supporting_fixits ();