Skip to content

Commit bc65bad

Browse files
mgulickDavid Malcolm
authored and
David Malcolm
committed
PR preprocessor/83173: Enhance -fdump-internal-locations output
gcc/ChangeLog: 2018-11-27 Mike Gulick <[email protected]> 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 <[email protected]> PR preprocessor/83173 * location-example.txt: Update example -fdump-internal-locations output. From-SVN: r266520
1 parent fb51a3a commit bc65bad

7 files changed

+293
-192
lines changed

gcc/ChangeLog

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2018-11-27 Mike Gulick <[email protected]>
2+
3+
PR preprocessor/83173
4+
* input.c (dump_location_info): Dump reason and included_from
5+
fields from line_map_ordinary struct. Fix indentation when
6+
location > 5 digits.
7+
* diagnostic-show-locus.c (num_digits, num_digits): Move to
8+
diagnostic.c to allow it to be utilized by input.c.
9+
* diagnostic.c (num_digits, selftest::test_num_digits): Moved
10+
here.
11+
(selftest::diagnostic_c_tests): Run selftest::test_num_digits.
12+
* diagnostic.h (num_digits): Add extern definition.
13+
114
2018-11-27 Fredrik Noring <[email protected]>
215

316
* config/mips/mips.c (mips_reorg_process_insns)

gcc/diagnostic-show-locus.c

-51
Original file line numberDiff line numberDiff line change
@@ -819,56 +819,6 @@ fixit_cmp (const void *p_a, const void *p_b)
819819
return hint_a->get_start_loc () - hint_b->get_start_loc ();
820820
}
821821

822-
/* Get the number of digits in the decimal representation
823-
of VALUE. */
824-
825-
static int
826-
num_digits (int value)
827-
{
828-
/* Perhaps simpler to use log10 for this, but doing it this way avoids
829-
using floating point. */
830-
gcc_assert (value >= 0);
831-
832-
if (value == 0)
833-
return 1;
834-
835-
int digits = 0;
836-
while (value > 0)
837-
{
838-
digits++;
839-
value /= 10;
840-
}
841-
return digits;
842-
}
843-
844-
845-
#if CHECKING_P
846-
847-
/* Selftest for num_digits. */
848-
849-
static void
850-
test_num_digits ()
851-
{
852-
ASSERT_EQ (1, num_digits (0));
853-
ASSERT_EQ (1, num_digits (9));
854-
ASSERT_EQ (2, num_digits (10));
855-
ASSERT_EQ (2, num_digits (99));
856-
ASSERT_EQ (3, num_digits (100));
857-
ASSERT_EQ (3, num_digits (999));
858-
ASSERT_EQ (4, num_digits (1000));
859-
ASSERT_EQ (4, num_digits (9999));
860-
ASSERT_EQ (5, num_digits (10000));
861-
ASSERT_EQ (5, num_digits (99999));
862-
ASSERT_EQ (6, num_digits (100000));
863-
ASSERT_EQ (6, num_digits (999999));
864-
ASSERT_EQ (7, num_digits (1000000));
865-
ASSERT_EQ (7, num_digits (9999999));
866-
ASSERT_EQ (8, num_digits (10000000));
867-
ASSERT_EQ (8, num_digits (99999999));
868-
}
869-
870-
#endif /* #if CHECKING_P */
871-
872822
/* Implementation of class layout. */
873823

874824
/* Constructor for class layout.
@@ -3761,7 +3711,6 @@ void
37613711
diagnostic_show_locus_c_tests ()
37623712
{
37633713
test_line_span ();
3764-
test_num_digits ();
37653714

37663715
test_layout_range_for_single_point ();
37673716
test_layout_range_for_single_line ();

gcc/diagnostic.c

+46
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,27 @@ diagnostic_report_diagnostic (diagnostic_context *context,
10351035
return true;
10361036
}
10371037

1038+
/* Get the number of digits in the decimal representation of VALUE. */
1039+
1040+
int
1041+
num_digits (int value)
1042+
{
1043+
/* Perhaps simpler to use log10 for this, but doing it this way avoids
1044+
using floating point. */
1045+
gcc_assert (value >= 0);
1046+
1047+
if (value == 0)
1048+
return 1;
1049+
1050+
int digits = 0;
1051+
while (value > 0)
1052+
{
1053+
digits++;
1054+
value /= 10;
1055+
}
1056+
return digits;
1057+
}
1058+
10381059
/* Given a partial pathname as input, return another pathname that
10391060
shares no directory elements with the pathname of __FILE__. This
10401061
is used by fancy_abort() to print `Internal compiler error in expr.c'
@@ -1785,6 +1806,29 @@ test_diagnostic_get_location_text ()
17851806
progname = old_progname;
17861807
}
17871808

1809+
/* Selftest for num_digits. */
1810+
1811+
static void
1812+
test_num_digits ()
1813+
{
1814+
ASSERT_EQ (1, num_digits (0));
1815+
ASSERT_EQ (1, num_digits (9));
1816+
ASSERT_EQ (2, num_digits (10));
1817+
ASSERT_EQ (2, num_digits (99));
1818+
ASSERT_EQ (3, num_digits (100));
1819+
ASSERT_EQ (3, num_digits (999));
1820+
ASSERT_EQ (4, num_digits (1000));
1821+
ASSERT_EQ (4, num_digits (9999));
1822+
ASSERT_EQ (5, num_digits (10000));
1823+
ASSERT_EQ (5, num_digits (99999));
1824+
ASSERT_EQ (6, num_digits (100000));
1825+
ASSERT_EQ (6, num_digits (999999));
1826+
ASSERT_EQ (7, num_digits (1000000));
1827+
ASSERT_EQ (7, num_digits (9999999));
1828+
ASSERT_EQ (8, num_digits (10000000));
1829+
ASSERT_EQ (8, num_digits (99999999));
1830+
}
1831+
17881832
/* Run all of the selftests within this file. */
17891833

17901834
void
@@ -1796,6 +1840,8 @@ diagnostic_c_tests ()
17961840
test_print_parseable_fixits_remove ();
17971841
test_print_parseable_fixits_replace ();
17981842
test_diagnostic_get_location_text ();
1843+
test_num_digits ();
1844+
17991845
}
18001846

18011847
} // namespace selftest

gcc/diagnostic.h

+3
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,7 @@ extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
421421
extern void diagnostic_output_format_init (diagnostic_context *,
422422
enum diagnostics_output_format);
423423

424+
/* Compute the number of digits in the decimal representation of an integer. */
425+
extern int num_digits (int);
426+
424427
#endif /* ! GCC_DIAGNOSTIC_H */

gcc/input.c

+40-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see
2121
#include "system.h"
2222
#include "coretypes.h"
2323
#include "intl.h"
24+
#include "diagnostic.h"
2425
#include "diagnostic-core.h"
2526
#include "selftest.h"
2627
#include "cpplib.h"
@@ -1067,6 +1068,37 @@ dump_location_info (FILE *stream)
10671068
map->m_column_and_range_bits - map->m_range_bits);
10681069
fprintf (stream, " range bits: %i\n",
10691070
map->m_range_bits);
1071+
const char * reason;
1072+
switch (map->reason) {
1073+
case LC_ENTER:
1074+
reason = "LC_ENTER";
1075+
break;
1076+
case LC_LEAVE:
1077+
reason = "LC_LEAVE";
1078+
break;
1079+
case LC_RENAME:
1080+
reason = "LC_RENAME";
1081+
break;
1082+
case LC_RENAME_VERBATIM:
1083+
reason = "LC_RENAME_VERBATIM";
1084+
break;
1085+
case LC_ENTER_MACRO:
1086+
reason = "LC_RENAME_MACRO";
1087+
break;
1088+
default:
1089+
reason = "Unknown";
1090+
}
1091+
fprintf (stream, " reason: %d (%s)\n", map->reason, reason);
1092+
1093+
const line_map_ordinary *includer_map
1094+
= linemap_included_from_linemap (line_table, map);
1095+
fprintf (stream, " included from location: %d",
1096+
linemap_included_from (map));
1097+
if (includer_map) {
1098+
fprintf (stream, " (in ordinary map %d)",
1099+
int (includer_map - line_table->info_ordinary.maps));
1100+
}
1101+
fprintf (stream, "\n");
10701102

10711103
/* Render the span of source lines that this "map" covers. */
10721104
for (location_t loc = MAP_START_LOCATION (map);
@@ -1100,7 +1132,14 @@ dump_location_info (FILE *stream)
11001132
if (max_col > line_text.length ())
11011133
max_col = line_text.length () + 1;
11021134

1103-
int indent = 14 + strlen (exploc.file);
1135+
int len_lnum = num_digits (exploc.line);
1136+
if (len_lnum < 3)
1137+
len_lnum = 3;
1138+
int len_loc = num_digits (loc);
1139+
if (len_loc < 5)
1140+
len_loc = 5;
1141+
1142+
int indent = 6 + strlen (exploc.file) + len_lnum + len_loc;
11041143

11051144
/* Thousands. */
11061145
if (end_location > 999)

libcpp/ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2018-11-27 Mike Gulick <[email protected]>
2+
3+
PR preprocessor/83173
4+
* location-example.txt: Update example -fdump-internal-locations
5+
output.
6+
17
2018-11-27 Mike Gulick <[email protected]>
28

39
PR preprocessor/83173

0 commit comments

Comments
 (0)