Commit bc65bad2 by Mike Gulick Committed by David Malcolm

PR preprocessor/83173: Enhance -fdump-internal-locations output

gcc/ChangeLog:
2018-11-27  Mike Gulick  <mgulick@mathworks.com>

	PR preprocessor/83173
	* input.c (dump_location_info): Dump reason and included_from
	fields from line_map_ordinary struct.  Fix indentation when
	location > 5 digits.
	* diagnostic-show-locus.c (num_digits, num_digits): Move to
	diagnostic.c to allow it to be utilized by input.c.
	* diagnostic.c (num_digits, selftest::test_num_digits): Moved
	here.
	(selftest::diagnostic_c_tests): Run selftest::test_num_digits.
	* diagnostic.h (num_digits): Add extern definition.

libcpp/ChangeLog:
2018-11-27  Mike Gulick  <mgulick@mathworks.com>

	PR preprocessor/83173
	* location-example.txt: Update example -fdump-internal-locations
	output.

From-SVN: r266520
parent fb51a3a8
2018-11-27 Mike Gulick <mgulick@mathworks.com>
PR preprocessor/83173
* input.c (dump_location_info): Dump reason and included_from
fields from line_map_ordinary struct. Fix indentation when
location > 5 digits.
* diagnostic-show-locus.c (num_digits, num_digits): Move to
diagnostic.c to allow it to be utilized by input.c.
* diagnostic.c (num_digits, selftest::test_num_digits): Moved
here.
(selftest::diagnostic_c_tests): Run selftest::test_num_digits.
* diagnostic.h (num_digits): Add extern definition.
2018-11-27 Fredrik Noring <noring@nocrew.org> 2018-11-27 Fredrik Noring <noring@nocrew.org>
* config/mips/mips.c (mips_reorg_process_insns) * config/mips/mips.c (mips_reorg_process_insns)
...@@ -819,56 +819,6 @@ fixit_cmp (const void *p_a, const void *p_b) ...@@ -819,56 +819,6 @@ fixit_cmp (const void *p_a, const void *p_b)
return hint_a->get_start_loc () - hint_b->get_start_loc (); return hint_a->get_start_loc () - hint_b->get_start_loc ();
} }
/* Get the number of digits in the decimal representation
of VALUE. */
static int
num_digits (int value)
{
/* Perhaps simpler to use log10 for this, but doing it this way avoids
using floating point. */
gcc_assert (value >= 0);
if (value == 0)
return 1;
int digits = 0;
while (value > 0)
{
digits++;
value /= 10;
}
return digits;
}
#if CHECKING_P
/* Selftest for num_digits. */
static void
test_num_digits ()
{
ASSERT_EQ (1, num_digits (0));
ASSERT_EQ (1, num_digits (9));
ASSERT_EQ (2, num_digits (10));
ASSERT_EQ (2, num_digits (99));
ASSERT_EQ (3, num_digits (100));
ASSERT_EQ (3, num_digits (999));
ASSERT_EQ (4, num_digits (1000));
ASSERT_EQ (4, num_digits (9999));
ASSERT_EQ (5, num_digits (10000));
ASSERT_EQ (5, num_digits (99999));
ASSERT_EQ (6, num_digits (100000));
ASSERT_EQ (6, num_digits (999999));
ASSERT_EQ (7, num_digits (1000000));
ASSERT_EQ (7, num_digits (9999999));
ASSERT_EQ (8, num_digits (10000000));
ASSERT_EQ (8, num_digits (99999999));
}
#endif /* #if CHECKING_P */
/* Implementation of class layout. */ /* Implementation of class layout. */
/* Constructor for class layout. /* Constructor for class layout.
...@@ -3761,7 +3711,6 @@ void ...@@ -3761,7 +3711,6 @@ void
diagnostic_show_locus_c_tests () diagnostic_show_locus_c_tests ()
{ {
test_line_span (); test_line_span ();
test_num_digits ();
test_layout_range_for_single_point (); test_layout_range_for_single_point ();
test_layout_range_for_single_line (); test_layout_range_for_single_line ();
......
...@@ -1035,6 +1035,27 @@ diagnostic_report_diagnostic (diagnostic_context *context, ...@@ -1035,6 +1035,27 @@ diagnostic_report_diagnostic (diagnostic_context *context,
return true; return true;
} }
/* Get the number of digits in the decimal representation of VALUE. */
int
num_digits (int value)
{
/* Perhaps simpler to use log10 for this, but doing it this way avoids
using floating point. */
gcc_assert (value >= 0);
if (value == 0)
return 1;
int digits = 0;
while (value > 0)
{
digits++;
value /= 10;
}
return digits;
}
/* Given a partial pathname as input, return another pathname that /* Given a partial pathname as input, return another pathname that
shares no directory elements with the pathname of __FILE__. This shares no directory elements with the pathname of __FILE__. This
is used by fancy_abort() to print `Internal compiler error in expr.c' is used by fancy_abort() to print `Internal compiler error in expr.c'
...@@ -1785,6 +1806,29 @@ test_diagnostic_get_location_text () ...@@ -1785,6 +1806,29 @@ test_diagnostic_get_location_text ()
progname = old_progname; progname = old_progname;
} }
/* Selftest for num_digits. */
static void
test_num_digits ()
{
ASSERT_EQ (1, num_digits (0));
ASSERT_EQ (1, num_digits (9));
ASSERT_EQ (2, num_digits (10));
ASSERT_EQ (2, num_digits (99));
ASSERT_EQ (3, num_digits (100));
ASSERT_EQ (3, num_digits (999));
ASSERT_EQ (4, num_digits (1000));
ASSERT_EQ (4, num_digits (9999));
ASSERT_EQ (5, num_digits (10000));
ASSERT_EQ (5, num_digits (99999));
ASSERT_EQ (6, num_digits (100000));
ASSERT_EQ (6, num_digits (999999));
ASSERT_EQ (7, num_digits (1000000));
ASSERT_EQ (7, num_digits (9999999));
ASSERT_EQ (8, num_digits (10000000));
ASSERT_EQ (8, num_digits (99999999));
}
/* Run all of the selftests within this file. */ /* Run all of the selftests within this file. */
void void
...@@ -1796,6 +1840,8 @@ diagnostic_c_tests () ...@@ -1796,6 +1840,8 @@ diagnostic_c_tests ()
test_print_parseable_fixits_remove (); test_print_parseable_fixits_remove ();
test_print_parseable_fixits_replace (); test_print_parseable_fixits_replace ();
test_diagnostic_get_location_text (); test_diagnostic_get_location_text ();
test_num_digits ();
} }
} // namespace selftest } // namespace selftest
......
...@@ -421,4 +421,7 @@ extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1; ...@@ -421,4 +421,7 @@ extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
extern void diagnostic_output_format_init (diagnostic_context *, extern void diagnostic_output_format_init (diagnostic_context *,
enum diagnostics_output_format); enum diagnostics_output_format);
/* Compute the number of digits in the decimal representation of an integer. */
extern int num_digits (int);
#endif /* ! GCC_DIAGNOSTIC_H */ #endif /* ! GCC_DIAGNOSTIC_H */
...@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see
#include "system.h" #include "system.h"
#include "coretypes.h" #include "coretypes.h"
#include "intl.h" #include "intl.h"
#include "diagnostic.h"
#include "diagnostic-core.h" #include "diagnostic-core.h"
#include "selftest.h" #include "selftest.h"
#include "cpplib.h" #include "cpplib.h"
...@@ -1067,6 +1068,37 @@ dump_location_info (FILE *stream) ...@@ -1067,6 +1068,37 @@ dump_location_info (FILE *stream)
map->m_column_and_range_bits - map->m_range_bits); map->m_column_and_range_bits - map->m_range_bits);
fprintf (stream, " range bits: %i\n", fprintf (stream, " range bits: %i\n",
map->m_range_bits); map->m_range_bits);
const char * reason;
switch (map->reason) {
case LC_ENTER:
reason = "LC_ENTER";
break;
case LC_LEAVE:
reason = "LC_LEAVE";
break;
case LC_RENAME:
reason = "LC_RENAME";
break;
case LC_RENAME_VERBATIM:
reason = "LC_RENAME_VERBATIM";
break;
case LC_ENTER_MACRO:
reason = "LC_RENAME_MACRO";
break;
default:
reason = "Unknown";
}
fprintf (stream, " reason: %d (%s)\n", map->reason, reason);
const line_map_ordinary *includer_map
= linemap_included_from_linemap (line_table, map);
fprintf (stream, " included from location: %d",
linemap_included_from (map));
if (includer_map) {
fprintf (stream, " (in ordinary map %d)",
int (includer_map - line_table->info_ordinary.maps));
}
fprintf (stream, "\n");
/* Render the span of source lines that this "map" covers. */ /* Render the span of source lines that this "map" covers. */
for (location_t loc = MAP_START_LOCATION (map); for (location_t loc = MAP_START_LOCATION (map);
...@@ -1100,7 +1132,14 @@ dump_location_info (FILE *stream) ...@@ -1100,7 +1132,14 @@ dump_location_info (FILE *stream)
if (max_col > line_text.length ()) if (max_col > line_text.length ())
max_col = line_text.length () + 1; max_col = line_text.length () + 1;
int indent = 14 + strlen (exploc.file); int len_lnum = num_digits (exploc.line);
if (len_lnum < 3)
len_lnum = 3;
int len_loc = num_digits (loc);
if (len_loc < 5)
len_loc = 5;
int indent = 6 + strlen (exploc.file) + len_lnum + len_loc;
/* Thousands. */ /* Thousands. */
if (end_location > 999) if (end_location > 999)
......
2018-11-27 Mike Gulick <mgulick@mathworks.com> 2018-11-27 Mike Gulick <mgulick@mathworks.com>
PR preprocessor/83173 PR preprocessor/83173
* location-example.txt: Update example -fdump-internal-locations
output.
2018-11-27 Mike Gulick <mgulick@mathworks.com>
PR preprocessor/83173
* files.c (_cpp_stack_include): Check if * files.c (_cpp_stack_include): Check if
line_table->highest_location is past current line before line_table->highest_location is past current line before
decrementing. decrementing.
......
...@@ -33,8 +33,11 @@ ORDINARY MAP: 0 ...@@ -33,8 +33,11 @@ ORDINARY MAP: 0
location_t interval: 32 <= loc < 64 location_t interval: 32 <= loc < 64
file: test.c file: test.c
starting at line: 1 starting at line: 1
column bits: 12 column and range bits: 12
column bits: 7
range bits: 5 range bits: 5
reason: 0 (LC_ENTER)
included from location: 0
test.c: 1|loc: 32|#include "test.h" test.c: 1|loc: 32|#include "test.h"
|69269258258148147 |69269258258148147
|46802468024680246 |46802468024680246
...@@ -43,186 +46,228 @@ ORDINARY MAP: 1 ...@@ -43,186 +46,228 @@ ORDINARY MAP: 1
location_t interval: 64 <= loc < 96 location_t interval: 64 <= loc < 96
file: <built-in> file: <built-in>
starting at line: 0 starting at line: 0
column and range bits: 0
column bits: 0 column bits: 0
range bits: 0 range bits: 0
reason: 2 (LC_RENAME)
included from location: 0
ORDINARY MAP: 2 ORDINARY MAP: 2
location_t interval: 96 <= loc < 128 location_t interval: 96 <= loc < 128
file: <command-line> file: <command-line>
starting at line: 0 starting at line: 0
column and range bits: 0
column bits: 0 column bits: 0
range bits: 0 range bits: 0
reason: 2 (LC_RENAME)
included from location: 0
ORDINARY MAP: 3 ORDINARY MAP: 3
location_t interval: 128 <= loc < 160128 location_t interval: 128 <= loc < 250240
file: /usr/include/stdc-predef.h file: /usr/include/stdc-predef.h
starting at line: 1 starting at line: 1
column bits: 12 column and range bits: 12
column bits: 7
range bits: 5 range bits: 5
reason: 0 (LC_ENTER)
included from location: 127 (in ordinary map 2)
(contents of /usr/include/stdc-predef.h snipped for brevity) (contents of /usr/include/stdc-predef.h snipped for brevity)
ORDINARY MAP: 4 ORDINARY MAP: 4
location_t interval: 160128 <= loc < 160160 location_t interval: 250240 <= loc < 250272
file: <command-line> file: <command-line>
starting at line: 32 starting at line: 32
column bits: 12 column and range bits: 12
column bits: 7
range bits: 5 range bits: 5
reason: 1 (LC_LEAVE)
included from location: 0
ORDINARY MAP: 5 ORDINARY MAP: 5
location_t interval: 160160 <= loc < 164256 location_t interval: 250272 <= loc < 254368
file: test.c file: test.c
starting at line: 1 starting at line: 1
column bits: 12 column and range bits: 12
column bits: 7
range bits: 5 range bits: 5
test.c: 1|loc:160160|#include "test.h" reason: 2 (LC_RENAME)
included from location: 0
test.c: 1|loc:250272|#include "test.h"
|00000000000000000 |00000000000000000
|12223334445556667 |33344445556667778
|92582581481470470 |03603692692582581
|24680246802468024 |46802468024680246
ORDINARY MAP: 6 ORDINARY MAP: 6
location_t interval: 164256 <= loc < 173280 location_t interval: 254368 <= loc < 266720
file: test.h file: test.h
starting at line: 1 starting at line: 1
column bits: 12 column and range bits: 12
column bits: 7
range bits: 5 range bits: 5
test.h: 1|loc:164256|extern int foo (); reason: 0 (LC_ENTER)
included from location: 250272 (in ordinary map 5)
test.h: 1|loc:254368|extern int foo ();
|444444444444444444 |444444444444444444
|233344455566677788 |444455566677788899
|825814814704703603 |036926925825814814
|802468024680246802 |024680246802468024
test.h: 2|loc:168352| test.h: 2|loc:258464|
|
|
|
|
test.h: 3|loc:262560|#define PLUS(A, B) A + B
|222222222222233333333333
|566677788899900011122223
|925825814814704703603692
|246802468024680246802468
test.h: 4|loc:266656|
| |
| |
| |
| |
test.h: 3|loc:172448|#define PLUS(A, B) A + B
|222222222222222223333333
|455566677788889990001112
|814704703603692692582581
|024680246802468024680246
ORDINARY MAP: 7 ORDINARY MAP: 7
location_t interval: 173280 <= loc < 202016 location_t interval: 266720 <= loc < 299520
file: test.c file: test.c
starting at line: 2 starting at line: 2
column bits: 12 column and range bits: 12
column bits: 7
range bits: 5 range bits: 5
test.c: 2|loc:173280| reason: 1 (LC_LEAVE)
included from location: 0
test.c: 2|loc:266720|
| |
| |
| |
| |
test.c: 3|loc:177376|int test.c: 3|loc:270816|int
|777 |000
|444 |889
|047 |481
|802 |802
test.c: 4|loc:181472|main (int argc, char **argv) test.c: 4|loc:274912|main (int argc, char **argv)
|1111111111111111222222222222 |4455555555555555555555555555
|5556666777888999000111222333 |9900011122223334445556667778
|0360369269258258148147047036 |4704703603692692582581481470
|4680246802468024680246802468 |4680246802468024680246802468
test.c: 5|loc:185568|{ test.c: 5|loc:279008|{
|5 |9
|6
|0 |0
|4
|0 |0
test.c: 6|loc:189664| int a = PLUS (1,2); test.c: 6|loc:283104| int a = PLUS (1,2);
|999999999900000000000 |333333333333333333333
|677788899900011122233 |112222333444555666777
|926925825814814704703 |360369269258258148147
|680246802468024680246 |680246802468024680246
test.c: 7|loc:193760| int b = PLUS (3,4); test.c: 7|loc:287200| int b = PLUS (3,4);
|333333344444444444444 |777777777777777777777
|788899900011122233344 |222333444555666777888
|925825814814704703603 |369269258258148147047
|246802468024680246802 |246802468024680246802
test.c: 8|loc:197856| return 0; test.c: 8|loc:291296| return 0;
|77778888888 |11111111111
|89990001112 |33344455566
|82581481470 |26925825814
|80246802468 |80246802468
test.c: 9|loc:201952|} test.c: 9|loc:295392|}
|1 |5
|9 |4
|8 |2
|4 |4
test.c: 10|loc:299488|
|
|
|
|
UNALLOCATED LOCATIONS UNALLOCATED LOCATIONS
location_t interval: 202016 <= loc < 2147483633 location_t interval: 299520 <= loc < 2147483632
MACRO 1: PLUS (7 tokens)
location_t interval: 2147483633 <= loc < 2147483640
test.c:7:11: note: expansion point is location 194115
int b = PLUS (3,4);
^~~~
map->start_location: 2147483633 MACRO 3: PLUS (7 tokens)
location_t interval: 2147483632 <= loc < 2147483639
test.c:7:11: note: expansion point is location 287555
7 | int b = PLUS (3,4);
| ^~~~
map->start_location: 2147483632
macro_locations: macro_locations:
0: 194304, 173088 0: 287744, 263200
test.c:7:17: note: token 0 has x-location == 194304 test.c:7:17: note: token 0 has x-location == 287744
int b = PLUS (3,4); 7 | int b = PLUS (3,4);
^ | ^
test.c:7:17: note: token 0 has y-location == 263200
1: 263264, 263264
In file included from test.c:1:
test.h:3:22: note: token 1 has x-location == y-location == 263264
3 | #define PLUS(A, B) A + B
| ^
2: 287808, 263328
test.c:7:19: note: token 2 has x-location == 287808
7 | int b = PLUS (3,4);
| ^
test.c:7:19: note: token 2 has y-location == 263328
3: 0, 0
cc1: note: token 3 has x-location == y-location == 0
4: 0, 0
cc1: note: token 4 has x-location == y-location == 0
5: 0, 0
cc1: note: token 5 has x-location == y-location == 0
6: 0, 0
cc1: note: token 6 has x-location == y-location == 0
test.c:7:17: note: token 0 has y-location == 173088 MACRO 2: PLUS (7 tokens)
1: 173152, 173152 location_t interval: 2147483639 <= loc < 2147483646
In file included from test.c:1:0: test.c:6:11: note: expansion point is location 283459
test.h:3:22: note: token 1 has x-location == y-location == 173152 6 | int a = PLUS (1,2);
#define PLUS(A, B) A + B | ^~~~
^ map->start_location: 2147483639
2: 194368, 173216
test.c:7:19: note: token 2 has x-location == 194368
int b = PLUS (3,4);
^
test.c:7:19: note: token 2 has y-location == 173216
3: 0, 2947526575
cc1: note: token 3 has x-location == 0
cc1: note: token 3 has y-location == 2947526575
4: 2947526575, 2947526575
x-location == y-location == 2947526575 encodes token # 800042942
5: 2947526575, 2947526575
x-location == y-location == 2947526575 encodes token # 800042942
6: 2947526575, 2947526575
x-location == y-location == 2947526575 encodes token # 800042942
MACRO 0: PLUS (7 tokens)
location_t interval: 2147483640 <= loc < 2147483647
test.c:6:11: note: expansion point is location 190019
int a = PLUS (1,2);
^~~~
map->start_location: 2147483640
macro_locations: macro_locations:
0: 190208, 173088 0: 283648, 263200
test.c:6:17: note: token 0 has x-location == 190208 test.c:6:17: note: token 0 has x-location == 283648
int a = PLUS (1,2); 6 | int a = PLUS (1,2);
^ | ^
test.c:6:17: note: token 0 has y-location == 263200
1: 263264, 263264
In file included from test.c:1:
test.h:3:22: note: token 1 has x-location == y-location == 263264
3 | #define PLUS(A, B) A + B
| ^
2: 283712, 263328
test.c:6:19: note: token 2 has x-location == 283712
6 | int a = PLUS (1,2);
| ^
test.c:6:19: note: token 2 has y-location == 263328
3: 0, 0
cc1: note: token 3 has x-location == y-location == 0
4: 0, 0
cc1: note: token 4 has x-location == y-location == 0
5: 0, 0
cc1: note: token 5 has x-location == y-location == 0
6: 0, 0
cc1: note: token 6 has x-location == y-location == 0
test.c:6:17: note: token 0 has y-location == 173088 MACRO 1: __GCC_IEC_559_COMPLEX (1 tokens)
1: 173152, 173152 location_t interval: 2147483646 <= loc < 2147483647
In file included from test.c:1:0: In file included from <command-line>:31:
test.h:3:22: note: token 1 has x-location == y-location == 173152 /usr/include/stdc-predef.h:45:6: note: expansion point is location 180564
#define PLUS(A, B) A + B 45 | # if __GCC_IEC_559_COMPLEX > 0
^ | ^~~~~~~~~~~~~~~~~~~~~
map->start_location: 2147483646
macro_locations:
0: 1, 1
<built-in>: note: token 0 has x-location == y-location == 1
2: 190272, 173216 MACRO 0: __GCC_IEC_559 (1 tokens)
test.c:6:19: note: token 2 has x-location == 190272 location_t interval: 2147483647 <= loc < 2147483648
int a = PLUS (1,2); /usr/include/stdc-predef.h:37:6: note: expansion point is location 147788
^ 37 | # if __GCC_IEC_559 > 0
| ^~~~~~~~~~~~~
test.c:6:19: note: token 2 has y-location == 173216 map->start_location: 2147483647
3: 0, 2947526575 macro_locations:
cc1: note: token 3 has x-location == 0 0: 1, 1
cc1: note: token 3 has y-location == 2947526575 <built-in>: note: token 0 has x-location == y-location == 1
4: 2947526575, 2947526575
x-location == y-location == 2947526575 encodes token # 800042935
5: 2947526575, 2947526575
x-location == y-location == 2947526575 encodes token # 800042935
6: 2947526575, 2947526575
x-location == y-location == 2947526575 encodes token # 800042935
MAX_LOCATION_T MAX_LOCATION_T
location_t interval: 2147483647 <= loc < 2147483648 location_t interval: 2147483647 <= loc < 2147483648
......
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