Fix the use of linemap_add and remove unnecessary kludge
authordodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 28 Aug 2011 20:14:46 +0000 (20:14 +0000)
committerdodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 28 Aug 2011 20:14:46 +0000 (20:14 +0000)
libcpp/

* line-map.c (linemap_add): Assert that reason must not be
LC_RENAME when called for the first time on a "main input file".

c-family/

* c-pch.c (c_common_read_pch): Call linemap_add with LC_ENTER as it's
the first time it's being called on this main TU.

gcc/lto/

* lto-lang.c (lto_init): Likewise.  Also, avoid calling
linemap_add twice.

gcc/fortran/

* scanner.c (load_file): Don't abuse LC_RENAME reason while
(indirectly) calling linemap_add.

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

gcc/c-family/ChangeLog
gcc/c-family/c-pch.c
gcc/fortran/ChangeLog
gcc/fortran/scanner.c
gcc/lto/ChangeLog
gcc/lto/lto-lang.c
libcpp/ChangeLog
libcpp/line-map.c

index 76569f1..44eae08 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-28  Dodji Seketeli  <dodji@redhat.com>
+
+       * c-pch.c (c_common_read_pch): Call linemap_add with LC_ENTER as
+       it's the first time it's being called on this main TU.
+
 2011-08-24  Richard Guenther  <rguenther@suse.de>
 
        PR c/49396
index 3c2fd18..7a289d6 100644 (file)
@@ -446,7 +446,7 @@ c_common_read_pch (cpp_reader *pfile, const char *name,
   fclose (f);
 
   line_table->trace_includes = saved_trace_includes;
-  linemap_add (line_table, LC_RENAME, 0, saved_loc.file, saved_loc.line);
+  linemap_add (line_table, LC_ENTER, 0, saved_loc.file, saved_loc.line);
 
   /* Give the front end a chance to take action after a PCH file has
      been loaded.  */
index 08c68ad..a9b85b2 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-28  Dodji Seketeli  <dodji@redhat.com>
+
+       * scanner.c (load_file): Don't abuse LC_RENAME reason while
+       (indirectly) calling linemap_add.
+
 2011-08-26  Jakub Jelinek  <jakub@redhat.com>
 
        * trans-decl.c (get_proc_pointer_decl): Set DECL_TLS_MODEL
index 0c127d4..120d550 100644 (file)
@@ -1887,6 +1887,11 @@ load_file (const char *realfilename, const char *displayedname, bool initial)
   int len, line_len;
   bool first_line;
   const char *filename;
+  /* If realfilename and displayedname are different and non-null then
+     surely realfilename is the preprocessed form of
+     displayedname.  */
+  bool preprocessed_p = (realfilename && displayedname
+                        && strcmp (realfilename, displayedname));
 
   filename = displayedname ? displayedname : realfilename;
 
@@ -1925,9 +1930,24 @@ load_file (const char *realfilename, const char *displayedname, bool initial)
        }
     }
 
-  /* Load the file.  */
+  /* Load the file.
 
-  f = get_file (filename, initial ? LC_RENAME : LC_ENTER);
+     A "non-initial" file means a file that is being included.  In
+     that case we are creating an LC_ENTER map.
+
+     An "initial" file means a main file; one that is not included.
+     That file has already got at least one (surely more) line map(s)
+     created by gfc_init.  So the subsequent map created in that case
+     must have LC_RENAME reason.
+
+     This latter case is not true for a preprocessed file.  In that
+     case, although the file is "initial", the line maps created by
+     gfc_init was used during the preprocessing of the file.  Now that
+     the preprocessing is over and we are being fed the result of that
+     preprocessing, we need to create a brand new line map for the
+     preprocessed file, so the reason is going to be LC_ENTER.  */
+
+  f = get_file (filename, (initial && !preprocessed_p) ? LC_RENAME : LC_ENTER);
   if (!initial)
     add_file_change (f->filename, f->inclusion_line);
   current_file = f;
index 4890390..6e1e187 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-28  Dodji Seketeli  <dodji@redhat.com>
+
+       * lto-lang.c (lto_init): Likewise.  Also, avoid calling
+       linemap_add twice.
+
 2011-08-11  Martin Jambor  <mjambor@suse.cz>
 
        * lto.c (uniquify_nodes): Use main variant's BINFO too.
index 83c41e6..d469fb9 100644 (file)
@@ -1081,8 +1081,7 @@ lto_init (void)
   flag_generate_lto = flag_wpa;
 
   /* Initialize libcpp line maps for gcc_assert to work.  */
-  linemap_add (line_table, LC_RENAME, 0, NULL, 0);
-  linemap_add (line_table, LC_RENAME, 0, NULL, 0);
+  linemap_add (line_table, LC_ENTER, 0, NULL, 0);
 
   /* Create the basic integer types.  */
   build_common_tree_nodes (flag_signed_char, /*short_double=*/false);
index 8a5e899..4ecda03 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-28  Dodji Seketeli  <dodji@redhat.com>
+
+       * line-map.c (linemap_add): Assert that reason must not be
+       LC_RENAME when called for the first time on a "main input file".
+
 2011-08-22  Gabriel Charette  <gchare@google.com>
 
        * init.c (cpp_create_reader): Inititalize forced_token_location_p.
index dd3f11c..2a0749a 100644 (file)
@@ -114,11 +114,10 @@ linemap_add (struct line_maps *set, enum lc_reason reason,
   if (reason == LC_RENAME_VERBATIM)
     reason = LC_RENAME;
 
-  /* If we don't keep our line maps consistent, we can easily
-     segfault.  Don't rely on the client to do it for us.  */
-  if (set->depth == 0)
-    reason = LC_ENTER;
-  else if (reason == LC_LEAVE)
+  if (set->depth == 0 && reason == LC_RENAME)
+    abort ();
+
+  if (reason == LC_LEAVE)
     {
       struct line_map *from;
       bool error;