]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[PATCH] line-map include-from representation
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 8 Aug 2018 18:13:00 +0000 (18:13 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 8 Aug 2018 18:13:00 +0000 (18:13 +0000)
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00554.html
Make linemap::included_from a location
libcpp/
* include/line-map.h (struct line_map_ordinary): Replace
included_from map index with included_at source_location.
(ORDINARY_MAP_INCLUDER_FILE_INDEX): Delete.
(LAST_SOURCE_LINE_LOCATION): Delete.
(LAST_SOURCE_LINE, LAST_SOURCE_COLUMN): Delete.
(linemap_included_from): New.
(linemap_included_from_linemap): Declare.
(MAIN_FILE_P): Adjust.
* line-map.c (linemap_included_from_linemap): New.
(lonemap_check_files_exited): Use linemap_included_at.
(linemap_add): Adjust inclusion setting.
(linemap_dump, linemap_dump_location): Adjust.
* directives.c (do_linemarker): Use linemap_included_at.
gcc/
* diagnostic.c (diagnostic_report_current_module): Use
linemap_included_from & linemap_included_from_linemap.
gcc/c-family/
* c-common.c (try_to_locate_new_include_inertion_point): Use
linemap_included_from_linemap.
* c-lex.c (fe_file_change): Use linemap_included_from.
* c-ppoutput.c (pp_file_change): Likewise.
gcc/fortran/
* cpp.c (cb_file_change): Use linemap_included_from.
gcc/testsuite/
* c-c++-common/inc-from-1a.h, c-c++-common/inc-from-1b.h,
c-c++-common/inc-from-1.c: New

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263429 138bc75d-0d04-0410-961f-82ee72b054a4

16 files changed:
gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c-family/c-lex.c
gcc/c-family/c-ppoutput.c
gcc/diagnostic.c
gcc/fortran/ChangeLog
gcc/fortran/cpp.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/inc-from-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/inc-from-1a.h [new file with mode: 0644]
gcc/testsuite/c-c++-common/inc-from-1b.h [new file with mode: 0644]
libcpp/ChangeLog
libcpp/directives.c
libcpp/include/line-map.h
libcpp/line-map.c

index 3c9aea6c52f4b28dc12b6b053b5c14348d7853ed..64704bcd6d80b5559fb34c6b8687a58f055d0e3e 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-08  Nathan Sidwell  <nathan@acm.org>
+
+       * diagnostic.c (diagnostic_report_current_module): Use
+       linemap_included_from & linemap_included_from_linemap.
+
 2018-08-08  Hongbo Zhang  <hongbo.zhang@linaro.org>
 
        * config/aarch64/aarch64-cores.def: Add phecda core.
index d5e5fff3b47580449054163a04ccc074e55ec081..aa7aada317af42c4b163c504da3593add0a0b31d 100644 (file)
@@ -1,3 +1,10 @@
+2018-08-08  Nathan Sidwell  <nathan@acm.org>
+
+       * c-common.c (try_to_locate_new_include_inertion_point): Use
+       linemap_included_from_linemap.
+       * c-lex.c (fe_file_change): Use linemap_included_from.
+       * c-ppoutput.c (pp_file_change): Likewise.
+
 2018-08-01  Martin Sebor  <msebor@redhat.com>
 
        PR tree-optimization/86650
index d919605744e0c2e118896d3bc2ce41701a69db50..91e60f3268a8bf7a2e445dc8ad5e3e11676a5b74 100644 (file)
@@ -8413,8 +8413,8 @@ try_to_locate_new_include_insertion_point (const char *file, location_t loc)
       const line_map_ordinary *ord_map
        = LINEMAPS_ORDINARY_MAP_AT (line_table, i);
 
-      const line_map_ordinary *from = INCLUDED_FROM (line_table, ord_map);
-      if (from)
+      if (const line_map_ordinary *from
+         = linemap_included_from_linemap (line_table, ord_map))
        if (from->to_file == file)
          {
            last_include_ord_map = from;
index 074c2d2b86e34ae29e6de7abd826971439c50639..ac58335cf3ad908509c321556402cb98b378826e 100644 (file)
@@ -199,7 +199,7 @@ fe_file_change (const line_map_ordinary *new_map)
         we already did in compile_file.  */
       if (!MAIN_FILE_P (new_map))
        {
-         unsigned int included_at = LAST_SOURCE_LINE_LOCATION (new_map - 1);
+         location_t included_at = linemap_included_from (new_map);
          int line = 0;
          if (included_at > BUILTINS_LOCATION)
            line = SOURCE_LINE (new_map - 1, included_at);
index 8c525caf28daa9e66652a8d9f6e38fe707210583..b8fc1c6dad931c1f53dee78082a3034a0e241085 100644 (file)
@@ -663,11 +663,9 @@ pp_file_change (const line_map_ordinary *map)
          /* Bring current file to correct line when entering a new file.  */
          if (map->reason == LC_ENTER)
            {
-             const line_map_ordinary *from = INCLUDED_FROM (line_table, map);
-             maybe_print_line (LAST_SOURCE_LINE_LOCATION (from));
+             maybe_print_line (linemap_included_from (map));
+             flags = " 1";
            }
-         if (map->reason == LC_ENTER)
-           flags = " 1";
          else if (map->reason == LC_LEAVE)
            flags = " 2";
          print_line (map->start_location, flags);
index 5205944738a0e9ee8834d7d8a79ceebbfea3abb8..3d7f164f94ed6e2b5ae44be3599e94d8e4099326 100644 (file)
@@ -590,9 +590,10 @@ diagnostic_report_current_module (diagnostic_context *context, location_t where)
          bool first = true;
          do
            {
-             map = INCLUDED_FROM (line_table, map);
+             where = linemap_included_from (map);
+             map = linemap_included_from_linemap (line_table, map);
              const char *line_col
-               = maybe_line_and_column (LAST_SOURCE_LINE (map),
+               = maybe_line_and_column (SOURCE_LINE (map, where),
                                         first && context->show_column
                                         ? SOURCE_COLUMN (map, where) : 0);
              static const char *const msgs[] =
index db0fe9d2465916a9451602b2894d326d1000f59b..705150962e9c78d23469971070e670a003a1c82a 100644 (file)
@@ -1,3 +1,7 @@
+2018-08-08  Nathan Sidwell  <nathan@acm.org>
+
+       * cpp.c (cb_file_change): Use linemap_included_from.
+
 2018-08-07  Cesar Philippidis  <cesar@codesourcery.com>
 
        * trans-stmt.h: Remove stale reference to trans-openacc.c.
index 82e890f015c80899897fff232629624d20ba3f51..4320461d07c940fcacd7b9c05336f3d057aac721 100644 (file)
@@ -881,10 +881,7 @@ cb_file_change (cpp_reader * ARG_UNUSED (pfile), const line_map_ordinary *map)
        {
          /* Bring current file to correct line when entering a new file.  */
          if (map->reason == LC_ENTER)
-           {
-             const line_map_ordinary *from = INCLUDED_FROM (line_table, map);
-             maybe_print_line (LAST_SOURCE_LINE_LOCATION (from));
-           }
+           maybe_print_line (linemap_included_from (map));
          if (map->reason == LC_ENTER)
            flags = " 1";
          else if (map->reason == LC_LEAVE)
index 472e6a9aa3e3f7f717f9627636be1948a832bcbe..12f842592d3747c3116211ae9928fdff3de87e47 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-08  Nathan Sidwell  <nathan@acm.org>
+
+       * c-c++-common/inc-from-1a.h, c-c++-common/inc-from-1b.h,
+       c-c++-common/inc-from-1.c: New
+
 2018-08-08  Andreas Krebbel  <krebbel@linux.ibm.com>
 
        PR target/85295
diff --git a/gcc/testsuite/c-c++-common/inc-from-1.c b/gcc/testsuite/c-c++-common/inc-from-1.c
new file mode 100644 (file)
index 0000000..7e95c2a
--- /dev/null
@@ -0,0 +1,5 @@
+#include "inc-from-1b.h"
+
+/* { dg-error "" ""  { target *-*-* } 1 } */
+
+/* { dg-regexp "In file included from \[^\n]*inc-from-1b.h:1,\n *from \[^\n]*inc-from-1.c:1:\n" } */
diff --git a/gcc/testsuite/c-c++-common/inc-from-1a.h b/gcc/testsuite/c-c++-common/inc-from-1a.h
new file mode 100644 (file)
index 0000000..684e812
--- /dev/null
@@ -0,0 +1 @@
+void bleah;
diff --git a/gcc/testsuite/c-c++-common/inc-from-1b.h b/gcc/testsuite/c-c++-common/inc-from-1b.h
new file mode 100644 (file)
index 0000000..40fae4a
--- /dev/null
@@ -0,0 +1 @@
+#include "inc-from-1a.h"
index 50fa2535888185c4f73800e3c99dd508192e23ae..3eaebfd812f28d6a8c7f2b2127be0def45832650 100644 (file)
@@ -1,3 +1,21 @@
+2018-08-08  Nathan Sidwell  <nathan@acm.org>
+
+       Make linemap::included_from a location
+       libcpp/
+       * include/line-map.h (struct line_map_ordinary): Replace
+       included_from map index with included_at source_location.
+       (ORDINARY_MAP_INCLUDER_FILE_INDEX): Delete.
+       (LAST_SOURCE_LINE_LOCATION): Delete.
+       (LAST_SOURCE_LINE, LAST_SOURCE_COLUMN): Delete.
+       (linemap_included_from): New.
+       (linemap_included_from_linemap): Declare.
+       (MAIN_FILE_P): Adjust.
+       * line-map.c (linemap_included_from_linemap): New.
+       (lonemap_check_files_exited): Use linemap_included_at.
+       (linemap_add): Adjust inclusion setting.
+       (linemap_dump, linemap_dump_location): Adjust.
+       * directives.c (do_linemarker): Use linemap_included_at.
+
 2018-08-07  Nathan Sidwell  <nathan@acm.org>
 
        * line-map.c: (linemap_init): Set default allocator here.
index bf13ada14ee068d94f2dd0d6c97939f516056b70..352c59150d7bcb4e4d6c83b7487efce96ac6fbb0 100644 (file)
@@ -1088,10 +1088,10 @@ do_linemarker (cpp_reader *pfile)
       /* Reread map since cpp_get_token can invalidate it with a
         reallocation.  */
       map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
-      const line_map_ordinary *from;      
+      const line_map_ordinary *from
+       = linemap_included_from_linemap (line_table, map);
       if (MAIN_FILE_P (map)
-         || (new_file
-             && (from = INCLUDED_FROM (pfile->line_table, map)) != NULL
+         || (from
              && filename_cmp (ORDINARY_MAP_FILE_NAME (from), new_file) != 0))
        {
          cpp_warning (pfile, CPP_W_NONE,
index a4baa492a56b246aead754f6e56732460d3b9107..1061d201389facce8e12ed38b1fc16d20da3a595 100644 (file)
@@ -440,10 +440,10 @@ struct GTY((tag ("1"))) line_map_ordinary : public line_map {
   const char *to_file;
   linenum_type to_line;
 
-  /* An index into the set that gives the line mapping at whose end
-     the current one was included.  File(s) at the bottom of the
-     include stack have this set to -1.  */
-  int included_from;
+  /* Location from whence this line map was included.  For regular
+     #includes, this location will be the last location of a map.  For
+     outermost file, this is 0.  */
+  source_location included_from;
 
   /* Size is 20 or 24 bytes, no padding  */
 };
@@ -634,17 +634,6 @@ ORDINARY_MAP_STARTING_LINE_NUMBER (const line_map_ordinary *ord_map)
   return ord_map->to_line;
 }
 
-/* Get the index of the ordinary map at whose end
-   ordinary map MAP was included.
-
-   File(s) at the bottom of the include stack have this set.  */
-
-inline int
-ORDINARY_MAP_INCLUDER_FILE_INDEX (const line_map_ordinary *ord_map)
-{
-  return ord_map->included_from;
-}
-
 /* Return a positive value if map encodes locations from a system
    header, 0 otherwise. Returns 1 if ordinary map MAP encodes locations
    in a system header and 2 if it encodes locations in a C system header
@@ -1192,51 +1181,23 @@ SOURCE_COLUMN (const line_map_ordinary *ord_map, source_location loc)
          & ((1 << ord_map->m_column_and_range_bits) - 1)) >> ord_map->m_range_bits;
 }
 
-/* Return the location of the last source line within an ordinary
-   map.  */
-inline source_location
-LAST_SOURCE_LINE_LOCATION (const line_map_ordinary *map)
-{
-  return (((map[1].start_location - 1
-           - map->start_location)
-          & ~((1 << map->m_column_and_range_bits) - 1))
-         + map->start_location);
-}
-
-/* Returns the last source line number within an ordinary map.  This
-   is the (last) line of the #include, or other directive, that caused
-   a map change.  */
-inline linenum_type
-LAST_SOURCE_LINE (const line_map_ordinary *map)
-{
-  return SOURCE_LINE (map, LAST_SOURCE_LINE_LOCATION (map));
-}
 
-/* Return the last column number within an ordinary map.  */
-
-inline linenum_type
-LAST_SOURCE_COLUMN (const line_map_ordinary *map)
+inline source_location
+linemap_included_from (const line_map_ordinary *ord_map)
 {
-  return SOURCE_COLUMN (map, LAST_SOURCE_LINE_LOCATION (map));
+  return ord_map->included_from;
 }
 
-/* Returns the map a given map was included from, or NULL if the map
-   belongs to the main file, i.e, a file that wasn't included by
-   another one.  */
-inline line_map_ordinary *
-INCLUDED_FROM (struct line_maps *set, const line_map_ordinary *ord_map)
-{
-  return ((ord_map->included_from == -1)
-         ? NULL
-         : LINEMAPS_ORDINARY_MAP_AT (set, ord_map->included_from));
-}
+/* The linemap containing the included-from location of MAP.  */
+const line_map_ordinary *linemap_included_from_linemap
+  (line_maps *set, const line_map_ordinary *map);
 
 /* True if the map is at the bottom of the include stack.  */
 
 inline bool
 MAIN_FILE_P (const line_map_ordinary *ord_map)
 {
-  return ord_map->included_from < 0;
+  return ord_map->included_from == 0;
 }
 
 /* Encode and return a source_location from a column number. The
index a5dc485e79e3438165b6d6051b7cde4a076a3dac..555cd129a9c5541c012ed6e9168465201de18213 100644 (file)
@@ -355,17 +355,25 @@ linemap_init (struct line_maps *set,
   set->builtin_location = builtin_location;
 }
 
+/* Return the ordinary line map from whence MAP was included.  Returns
+   NULL if MAP was not an include.  */
+
+const line_map_ordinary *
+linemap_included_from_linemap (line_maps *set, const line_map_ordinary *map)
+{
+  return linemap_ordinary_map_lookup (set, linemap_included_from (map));
+}
+
 /* Check for and warn about line_maps entered but not exited.  */
 
 void
 linemap_check_files_exited (struct line_maps *set)
 {
-  const line_map_ordinary *map;
   /* Depending upon whether we are handling preprocessed input or
      not, this can be a user error or an ICE.  */
-  for (map = LINEMAPS_LAST_ORDINARY_MAP (set);
+  for (const line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (set);
        ! MAIN_FILE_P (map);
-       map = INCLUDED_FROM (set, map))
+       map = linemap_included_from_linemap (set, map))
     fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n",
             ORDINARY_MAP_FILE_NAME (map));
 }
@@ -494,19 +502,19 @@ linemap_add (struct line_maps *set, enum lc_reason reason,
   if (reason == LC_RENAME_VERBATIM)
     reason = LC_RENAME;
 
+  const line_map_ordinary *from = NULL;
   if (reason == LC_LEAVE)
     {
       /* When we are just leaving an "included" file, and jump to the next
         location inside the "includer" right after the #include
         "included", this variable points the map in use right before the
         #include "included", inside the same "includer" file.  */
-      line_map_ordinary *from;
 
       linemap_assert (!MAIN_FILE_P (map - 1));
       /* (MAP - 1) points to the map we are leaving. The
         map from which (MAP - 1) got included should be the map
         that comes right before MAP in the same file.  */
-      from = INCLUDED_FROM (set, map - 1);
+      from = linemap_included_from_linemap (set, map - 1);
 
       /* A TO_FILE of NULL is special - we use the natural values.  */
       if (to_file == NULL)
@@ -538,19 +546,24 @@ linemap_add (struct line_maps *set, enum lc_reason reason,
 
   if (reason == LC_ENTER)
     {
-      map->included_from =
-       set->depth == 0 ? -1 : (int) (LINEMAPS_ORDINARY_USED (set) - 2);
+      if (set->depth == 0)
+       map->included_from = 0;
+      else
+       /* The location of the end of the just-closed map.  */
+       map->included_from
+         = (((map[0].start_location - 1 - map[-1].start_location)
+             & ~((1 << map[-1].m_column_and_range_bits) - 1))
+            + map[-1].start_location);
       set->depth++;
       if (set->trace_includes)
        trace_include (set, map);
     }
   else if (reason == LC_RENAME)
-    map->included_from = ORDINARY_MAP_INCLUDER_FILE_INDEX (&map[-1]);
+    map->included_from = linemap_included_from (&map[-1]);
   else if (reason == LC_LEAVE)
     {
       set->depth--;
-      map->included_from =
-       ORDINARY_MAP_INCLUDER_FILE_INDEX (INCLUDED_FROM (set, map - 1));
+      map->included_from = linemap_included_from (from);
     }
 
   return map;
@@ -1761,17 +1774,13 @@ linemap_dump (FILE *stream, struct line_maps *set, unsigned ix, bool is_macro)
   if (!is_macro)
     {
       const line_map_ordinary *ord_map = linemap_check_ordinary (map);
-      unsigned includer_ix;
-      const line_map_ordinary *includer_map;
-
-      includer_ix = ORDINARY_MAP_INCLUDER_FILE_INDEX (ord_map);
-      includer_map = includer_ix < LINEMAPS_ORDINARY_USED (set)
-                    ? LINEMAPS_ORDINARY_MAP_AT (set, includer_ix)
-                    : NULL;
+      const line_map_ordinary *includer_map
+       = linemap_included_from_linemap (set, ord_map);
 
       fprintf (stream, "File: %s:%d\n", ORDINARY_MAP_FILE_NAME (ord_map),
               ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map));
-      fprintf (stream, "Included from: [%d] %s\n", includer_ix,
+      fprintf (stream, "Included from: [%d] %s\n",
+              includer_map ? int (includer_map - set->info_ordinary.maps) : -1,
               includer_map ? ORDINARY_MAP_FILE_NAME (includer_map) : "None");
     }
   else
@@ -1821,9 +1830,11 @@ linemap_dump_location (struct line_maps *set,
       if (e)
        from = "N/A";
       else
-       from = (INCLUDED_FROM (set, map))
-         ? LINEMAP_FILE (INCLUDED_FROM (set, map))
-         : "<NULL>";
+       {
+         const line_map_ordinary *from_map
+           = linemap_included_from_linemap (set, map);
+         from = from_map ? LINEMAP_FILE (from_map) : "<NULL>";
+       }
     }
 
   /* P: path, L: line, C: column, S: in-system-header, M: map address,