{
location_t pure_loc = get_pure_location (caret);
source_range src_range;
- src_range.m_start = start;
- src_range.m_finish = finish;
+ src_range.m_start = get_start (start);
+ src_range.m_finish = get_finish (finish);
location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
pure_loc,
src_range,
ASSERT_PRED1 (is_location_from_builtin_token, BUILTINS_LOCATION);
}
+/* Regression test for make_location.
+ Ensure that we use the caret locations of the start/finish, rather
+ than storing a packed or ad-hoc range as the start/finish. */
+
+static void
+test_make_location_nonpure_range_endpoints (const line_table_case &case_)
+{
+ /* Issue seen with testsuite/c-c++-common/Wlogical-not-parentheses-2.c
+ with C++ frontend.
+ ....................0000000001111111111222.
+ ....................1234567890123456789012. */
+ const char *content = " r += !aaa == bbb;\n";
+ temp_source_file tmp (SELFTEST_LOCATION, ".C", content);
+ line_table_test ltt (case_);
+ linemap_add (line_table, LC_ENTER, false, tmp.get_filename (), 1);
+
+ const location_t c11 = linemap_position_for_column (line_table, 11);
+ const location_t c12 = linemap_position_for_column (line_table, 12);
+ const location_t c13 = linemap_position_for_column (line_table, 13);
+ const location_t c14 = linemap_position_for_column (line_table, 14);
+ const location_t c21 = linemap_position_for_column (line_table, 21);
+
+ if (c21 > LINE_MAP_MAX_LOCATION_WITH_COLS)
+ return;
+
+ /* Use column 13 for the caret location, arbitrarily, to verify that we
+ handle start != caret. */
+ const location_t aaa = make_location (c13, c12, c14);
+ ASSERT_EQ (c13, get_pure_location (aaa));
+ ASSERT_EQ (c12, get_start (aaa));
+ ASSERT_FALSE (IS_ADHOC_LOC (get_start (aaa)));
+ ASSERT_EQ (c14, get_finish (aaa));
+ ASSERT_FALSE (IS_ADHOC_LOC (get_finish (aaa)));
+
+ /* Make a location using a location with a range as the start-point. */
+ const location_t not_aaa = make_location (c11, aaa, c14);
+ ASSERT_EQ (c11, get_pure_location (not_aaa));
+ /* It should use the start location of the range, not store the range
+ itself. */
+ ASSERT_EQ (c12, get_start (not_aaa));
+ ASSERT_FALSE (IS_ADHOC_LOC (get_start (not_aaa)));
+ ASSERT_EQ (c14, get_finish (not_aaa));
+ ASSERT_FALSE (IS_ADHOC_LOC (get_finish (not_aaa)));
+
+ /* Similarly, make a location with a range as the end-point. */
+ const location_t aaa_eq_bbb = make_location (c12, c12, c21);
+ ASSERT_EQ (c12, get_pure_location (aaa_eq_bbb));
+ ASSERT_EQ (c12, get_start (aaa_eq_bbb));
+ ASSERT_FALSE (IS_ADHOC_LOC (get_start (aaa_eq_bbb)));
+ ASSERT_EQ (c21, get_finish (aaa_eq_bbb));
+ ASSERT_FALSE (IS_ADHOC_LOC (get_finish (aaa_eq_bbb)));
+ const location_t not_aaa_eq_bbb = make_location (c11, c12, aaa_eq_bbb);
+ /* It should use the finish location of the range, not store the range
+ itself. */
+ ASSERT_EQ (c11, get_pure_location (not_aaa_eq_bbb));
+ ASSERT_EQ (c12, get_start (not_aaa_eq_bbb));
+ ASSERT_FALSE (IS_ADHOC_LOC (get_start (not_aaa_eq_bbb)));
+ ASSERT_EQ (c21, get_finish (not_aaa_eq_bbb));
+ ASSERT_FALSE (IS_ADHOC_LOC (get_finish (not_aaa_eq_bbb)));
+}
+
/* Verify reading of input files (e.g. for caret-based diagnostics). */
static void
test_should_have_column_data_p ();
test_unknown_location ();
test_builtins ();
+ for_each_line_table_case (test_make_location_nonpure_range_endpoints);
for_each_line_table_case (test_accessing_ordinary_linemaps);
for_each_line_table_case (test_lexer);