Commit 741d3be5 by David Malcolm Committed by David Malcolm

input.c: add lexing selftests and a test matrix for line_table states

This patch adds explicit testing of lexing a source file,
generalizing this (and the test of ordinary line maps) over
a 2-dimensional test matrix covering:

  (1) line_table->default_range_bits: some frontends use a non-zero value
  and others use zero

  (2) the fallback modes within line-map.c: there are various threshold
  values for source_location/location_t beyond line-map.c changes
  behavior (disabling of the range-packing optimization, disabling
  of column-tracking).  We exercise these by starting the line_table
  at interesting values at or near these thresholds.

This helps ensures that location data works in all of these states,
and that (I hope) we don't have lingering bugs relating to the
transition between line_table states.

gcc/ChangeLog:
	* input.c: Include cpplib.h.
	(selftest::temp_source_file): New class.
	(selftest::temp_source_file::temp_source_file): New ctor.
	(selftest::temp_source_file::~temp_source_file): New dtor.
	(selftest::should_have_column_data_p): New function.
	(selftest::test_should_have_column_data_p): New function.
	(selftest::temp_line_table): New class.
	(selftest::temp_line_table::temp_line_table): New ctor.
	(selftest::temp_line_table::~temp_line_table): New dtor.
	(selftest::test_accessing_ordinary_linemaps): Add case_ param; use
	it to create a temp_line_table.
	(selftest::assert_loceq): Only verify LOCATION_COLUMN for
	locations that are known to have column data.
	(selftest::line_table_case): New struct.
	(selftest::test_reading_source_line): Move tempfile handling
	to class temp_source_file.
	(ASSERT_TOKEN_AS_TEXT_EQ): New macro.
	(selftest::assert_token_loc_eq): New function.
	(ASSERT_TOKEN_LOC_EQ): New macro.
	(selftest::test_lexer): New function.
	(selftest::boundary_locations): New array.
	(selftest::input_c_tests): Call test_should_have_column_data_p.
	Loop over a test matrix of interesting values of location and
	default_range_bits, calling test_lexer on each case in the matrix.
	Move call to test_accessing_ordinary_linemaps into the matrix.
	* selftest.h (ASSERT_EQ): Reimplement in terms of...
	(ASSERT_EQ_AT): New macro.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/location_overflow_plugin.c (plugin_init): Avoid
	hardcoding the values of LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES
	and LINE_MAP_MAX_LOCATION_WITH_COLS.

libcpp/ChangeLog:
	* include/line-map.h (LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES):
	Move here from line-map.c.
	(LINE_MAP_MAX_LOCATION_WITH_COLS): Likewise.
	* line-map.c (LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES): Move from
	here to line-map.h.
	(LINE_MAP_MAX_LOCATION_WITH_COLS): Likewise.

From-SVN: r238213
parent 92fa45b5
2016-07-11 David Malcolm <dmalcolm@redhat.com>
* input.c: Include cpplib.h.
(selftest::temp_source_file): New class.
(selftest::temp_source_file::temp_source_file): New ctor.
(selftest::temp_source_file::~temp_source_file): New dtor.
(selftest::should_have_column_data_p): New function.
(selftest::test_should_have_column_data_p): New function.
(selftest::temp_line_table): New class.
(selftest::temp_line_table::temp_line_table): New ctor.
(selftest::temp_line_table::~temp_line_table): New dtor.
(selftest::test_accessing_ordinary_linemaps): Add case_ param; use
it to create a temp_line_table.
(selftest::assert_loceq): Only verify LOCATION_COLUMN for
locations that are known to have column data.
(selftest::line_table_case): New struct.
(selftest::test_reading_source_line): Move tempfile handling
to class temp_source_file.
(ASSERT_TOKEN_AS_TEXT_EQ): New macro.
(selftest::assert_token_loc_eq): New function.
(ASSERT_TOKEN_LOC_EQ): New macro.
(selftest::test_lexer): New function.
(selftest::boundary_locations): New array.
(selftest::input_c_tests): Call test_should_have_column_data_p.
Loop over a test matrix of interesting values of location and
default_range_bits, calling test_lexer on each case in the matrix.
Move call to test_accessing_ordinary_linemaps into the matrix.
* selftest.h (ASSERT_EQ): Reimplement in terms of...
(ASSERT_EQ_AT): New macro.
2016-07-11 H.J. Lu <hongjiu.lu@intel.com>
PR target/71801
......
......@@ -129,13 +129,19 @@ extern int num_passes;
::selftest::pass if they are equal,
::selftest::fail if they are non-equal. */
#define ASSERT_EQ(EXPECTED, ACTUAL) \
#define ASSERT_EQ(EXPECTED, ACTUAL) \
ASSERT_EQ_AT ((SELFTEST_LOCATION), (EXPECTED), (ACTUAL))
/* Like ASSERT_EQ, but treat LOC as the effective location of the
selftest. */
#define ASSERT_EQ_AT(LOC, EXPECTED, ACTUAL) \
SELFTEST_BEGIN_STMT \
const char *desc = "ASSERT_EQ (" #EXPECTED ", " #ACTUAL ")"; \
if ((EXPECTED) == (ACTUAL)) \
::selftest::pass (SELFTEST_LOCATION, desc); \
::selftest::pass ((LOC), desc); \
else \
::selftest::fail (SELFTEST_LOCATION, desc); \
::selftest::fail ((LOC), desc); \
SELFTEST_END_STMT
/* Evaluate EXPECTED and ACTUAL and compare them with !=, calling
......
2016-07-11 David Malcolm <dmalcolm@redhat.com>
* gcc.dg/plugin/location_overflow_plugin.c (plugin_init): Avoid
hardcoding the values of LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES
and LINE_MAP_MAX_LOCATION_WITH_COLS.
2016-07-11 H.J. Lu <hongjiu.lu@intel.com>
PR target/71801
......
......@@ -87,11 +87,11 @@ plugin_init (struct plugin_name_args *plugin_info,
original_finalizer = diagnostic_finalizer (global_dc);
switch (base_location)
{
case 0x50000001:
case LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES + 1:
diagnostic_finalizer (global_dc) = verify_unpacked_ranges;
break;
case 0x60000001:
case LINE_MAP_MAX_LOCATION_WITH_COLS + 1:
diagnostic_finalizer (global_dc) = verify_no_columns;
break;
......
2016-07-11 David Malcolm <dmalcolm@redhat.com>
* include/line-map.h (LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES):
Move here from line-map.c.
(LINE_MAP_MAX_LOCATION_WITH_COLS): Likewise.
* line-map.c (LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES): Move from
here to line-map.h.
(LINE_MAP_MAX_LOCATION_WITH_COLS): Likewise.
2016-06-22 David Malcolm <dmalcolm@redhat.com>
* directives.c (do_include_common): Pass on "location" to
......
......@@ -260,6 +260,16 @@ typedef unsigned int linenum_type;
worked example in libcpp/location-example.txt. */
typedef unsigned int source_location;
/* Do not pack ranges if locations get higher than this.
If you change this, update:
gcc.dg/plugin/location-overflow-test-*.c. */
const source_location LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES = 0x50000000;
/* Do not track column numbers if locations get higher than this.
If you change this, update:
gcc.dg/plugin/location-overflow-test-*.c. */
const source_location LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000;
/* A range of source locations.
Ranges are closed:
......
......@@ -31,18 +31,6 @@ along with this program; see the file COPYING3. If not see
disabled). */
const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 12);
/* Do not pack ranges if locations get higher than this.
If you change this, update:
gcc.dg/plugin/location_overflow_plugin.c
gcc.dg/plugin/location-overflow-test-*.c. */
const source_location LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES = 0x50000000;
/* Do not track column numbers if locations get higher than this.
If you change this, update:
gcc.dg/plugin/location_overflow_plugin.c
gcc.dg/plugin/location-overflow-test-*.c. */
const source_location LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000;
/* Highest possible source location encoded within an ordinary or
macro map. */
const source_location LINE_MAP_MAX_SOURCE_LOCATION = 0x70000000;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment