aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c')
-rw-r--r--gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c97
1 files changed, 46 insertions, 51 deletions
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
index b4f12ba68c1..95078ce2f2b 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
@@ -140,6 +140,15 @@ custom_diagnostic_finalizer (diagnostic_context *context,
pp_flush (context->printer);
}
+/* Add a location to RICHLOC with caret==start at START, ranging to FINISH. */
+
+static void
+add_range (rich_location *richloc, location_t start, location_t finish,
+ bool show_caret_p)
+{
+ richloc->add_range (make_location (start, start, finish), show_caret_p);
+}
+
/* Exercise the diagnostic machinery to emit various warnings,
for use by diagnostic-test-show-locus-*.c.
@@ -165,8 +174,8 @@ test_show_locus (function *fun)
{
const int line = fnstart_line + 2;
rich_location richloc (line_table, get_loc (line, 15));
- richloc.add_range (get_loc (line, 10), get_loc (line, 14), false);
- richloc.add_range (get_loc (line, 16), get_loc (line, 16), false);
+ add_range (&richloc, get_loc (line, 10), get_loc (line, 14), false);
+ add_range (&richloc, get_loc (line, 16), get_loc (line, 16), false);
warning_at_rich_loc (&richloc, 0, "test");
}
@@ -174,10 +183,8 @@ test_show_locus (function *fun)
{
const int line = fnstart_line + 2;
rich_location richloc (line_table, get_loc (line, 24));
- richloc.add_range (get_loc (line, 6),
- get_loc (line, 22), false);
- richloc.add_range (get_loc (line, 26),
- get_loc (line, 43), false);
+ add_range (&richloc, get_loc (line, 6), get_loc (line, 22), false);
+ add_range (&richloc, get_loc (line, 26), get_loc (line, 43), false);
warning_at_rich_loc (&richloc, 0, "test");
}
@@ -185,10 +192,9 @@ test_show_locus (function *fun)
{
const int line = fnstart_line + 2;
rich_location richloc (line_table, get_loc (line + 1, 7));
- richloc.add_range (get_loc (line, 7),
- get_loc (line, 23), false);
- richloc.add_range (get_loc (line + 1, 9),
- get_loc (line + 1, 26), false);
+ add_range (&richloc, get_loc (line, 7), get_loc (line, 23), false);
+ add_range (&richloc, get_loc (line + 1, 9), get_loc (line + 1, 26),
+ false);
warning_at_rich_loc (&richloc, 0, "test");
}
@@ -196,22 +202,20 @@ test_show_locus (function *fun)
{
const int line = fnstart_line + 2;
rich_location richloc (line_table, get_loc (line + 5, 7));
- richloc.add_range (get_loc (line, 7),
- get_loc (line + 4, 65), false);
- richloc.add_range (get_loc (line + 5, 9),
- get_loc (line + 10, 61), false);
+ add_range (&richloc, get_loc (line, 7), get_loc (line + 4, 65), false);
+ add_range (&richloc, get_loc (line + 5, 9), get_loc (line + 10, 61),
+ false);
warning_at_rich_loc (&richloc, 0, "test");
}
- /* Example of a rich_location constructed directly from a
- source_range where the range is larger than one character. */
+ /* Example of a rich_location where the range is larger than
+ one character. */
if (0 == strcmp (fnname, "test_richloc_from_proper_range"))
{
const int line = fnstart_line + 2;
- source_range src_range;
- src_range.m_start = get_loc (line, 12);
- src_range.m_finish = get_loc (line, 16);
- rich_location richloc (src_range);
+ location_t start = get_loc (line, 12);
+ location_t finish = get_loc (line, 16);
+ rich_location richloc (line_table, make_location (start, start, finish));
warning_at_rich_loc (&richloc, 0, "test");
}
@@ -220,15 +224,9 @@ test_show_locus (function *fun)
if (0 == strcmp (fnname, "test_caret_within_proper_range"))
{
const int line = fnstart_line + 2;
- location_t caret = get_loc (line, 16);
- source_range src_range;
- src_range.m_start = get_loc (line, 12);
- src_range.m_finish = get_loc (line, 20);
- location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
- caret,
- src_range,
- NULL);
- warning_at (combined_loc, 0, "test");
+ warning_at (make_location (get_loc (line, 16), get_loc (line, 12),
+ get_loc (line, 20)),
+ 0, "test");
}
/* Example of a very wide line, where the information of interest
@@ -236,15 +234,9 @@ test_show_locus (function *fun)
if (0 == strcmp (fnname, "test_very_wide_line"))
{
const int line = fnstart_line + 2;
- location_t caret = get_loc (line, 94);
- source_range src_range;
- src_range.m_start = get_loc (line, 90);
- src_range.m_finish = get_loc (line, 98);
- location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
- caret,
- src_range,
- NULL);
- warning_at (combined_loc, 0, "test");
+ warning_at (make_location (get_loc (line, 94), get_loc (line, 90),
+ get_loc (line, 98)),
+ 0, "test");
}
/* Example of multiple carets. */
@@ -254,7 +246,7 @@ test_show_locus (function *fun)
location_t caret_a = get_loc (line, 7);
location_t caret_b = get_loc (line, 11);
rich_location richloc (line_table, caret_a);
- richloc.add_range (caret_b, caret_b, true);
+ add_range (&richloc, caret_b, caret_b, true);
global_dc->caret_chars[0] = 'A';
global_dc->caret_chars[1] = 'B';
warning_at_rich_loc (&richloc, 0, "test");
@@ -266,11 +258,10 @@ test_show_locus (function *fun)
if (0 == strcmp (fnname, "test_fixit_insert"))
{
const int line = fnstart_line + 2;
- source_range src_range;
- src_range.m_start = get_loc (line, 19);
- src_range.m_finish = get_loc (line, 22);
- rich_location richloc (src_range);
- richloc.add_fixit_insert (src_range.m_start, "{");
+ location_t start = get_loc (line, 19);
+ location_t finish = get_loc (line, 22);
+ rich_location richloc (line_table, make_location (start, start, finish));
+ richloc.add_fixit_insert (start, "{");
richloc.add_fixit_insert (get_loc (line, 23), "}");
warning_at_rich_loc (&richloc, 0, "example of insertion hints");
}
@@ -278,10 +269,12 @@ test_show_locus (function *fun)
if (0 == strcmp (fnname, "test_fixit_remove"))
{
const int line = fnstart_line + 2;
+ location_t start = get_loc (line, 8);
+ location_t finish = get_loc (line, 8);
+ rich_location richloc (line_table, make_location (start, start, finish));
source_range src_range;
- src_range.m_start = get_loc (line, 8);
- src_range.m_finish = get_loc (line, 8);
- rich_location richloc (src_range);
+ src_range.m_start = start;
+ src_range.m_finish = finish;
richloc.add_fixit_remove (src_range);
warning_at_rich_loc (&richloc, 0, "example of a removal hint");
}
@@ -289,10 +282,12 @@ test_show_locus (function *fun)
if (0 == strcmp (fnname, "test_fixit_replace"))
{
const int line = fnstart_line + 2;
+ location_t start = get_loc (line, 2);
+ location_t finish = get_loc (line, 19);
+ rich_location richloc (line_table, make_location (start, start, finish));
source_range src_range;
- src_range.m_start = get_loc (line, 2);
- src_range.m_finish = get_loc (line, 19);
- rich_location richloc (src_range);
+ src_range.m_start = start;
+ src_range.m_finish = finish;
richloc.add_fixit_replace (src_range, "gtk_widget_show_all");
warning_at_rich_loc (&richloc, 0, "example of a replacement hint");
}
@@ -310,7 +305,7 @@ test_show_locus (function *fun)
location_t caret_a = get_loc (line, 5);
location_t caret_b = get_loc (line - 1, 19);
rich_location richloc (line_table, caret_a);
- richloc.add_range (caret_b, caret_b, true);
+ richloc.add_range (caret_b, true);
global_dc->caret_chars[0] = '1';
global_dc->caret_chars[1] = '2';
warning_at_rich_loc (&richloc, 0, "test");