OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / c-pch.c
index 76e40fb..951ab1f 100644 (file)
@@ -1,11 +1,12 @@
 /* Precompiled header implementation for the C languages.
-   Copyright (C) 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GCC is distributed in the hope that it will be useful,
@@ -14,9 +15,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to
-the Free Software Foundation, 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
 #include "system.h"
@@ -34,6 +34,8 @@ Boston, MA 02110-1301, USA.  */
 #include "langhooks.h"
 #include "hosthooks.h"
 #include "target.h"
+#include "opts.h"
+#include "timevar.h"
 
 /* This is a list of flag variables that must match exactly, and their
    names for the error message.  The possible values for *flag_var must
@@ -45,7 +47,6 @@ static const struct c_pch_matching
   const char *flag_name;
 } pch_matching[] = {
   { &flag_exceptions, "-fexceptions" },
-  { &flag_unit_at_a_time, "-funit-at-a-time" }
 };
 
 enum {
@@ -93,10 +94,10 @@ static const char *
 get_ident (void)
 {
   static char result[IDENT_LENGTH];
-  static const char template[IDENT_LENGTH] = "gpch.013";
+  static const char templ[] = "gpch.013";
   static const char c_language_chars[] = "Co+O";
 
-  memcpy (result, template, IDENT_LENGTH);
+  memcpy (result, templ, IDENT_LENGTH);
   result[4] = c_language_chars[c_language];
 
   return result;
@@ -113,7 +114,7 @@ pch_init (void)
   FILE *f;
   struct c_pch_validity v;
   void *target_validity;
-  static const char partial_pch[IDENT_LENGTH] = "gpcWrite";
+  static const char partial_pch[] = "gpcWrite";
 
 #ifdef ASM_COMMENT_START
   if (flag_verbose_asm)
@@ -134,6 +135,7 @@ pch_init (void)
 
   gcc_assert (memcmp (executable_checksum, no_checksum, 16) != 0);
 
+  memset (&v, '\0', sizeof (v));
   v.debug_info_type = write_symbols;
   {
     size_t i;
@@ -177,6 +179,8 @@ c_common_write_pch (void)
   long written;
   struct c_pch_header h;
 
+  timevar_push (TV_PCH_SAVE);
+
   (*debug_hooks->handle_pch) (1);
 
   cpp_write_pch_deps (parse_in, pch_outfile);
@@ -210,13 +214,18 @@ c_common_write_pch (void)
     fatal_error ("can%'t seek in %s: %m", asm_file_name);
 
   gt_pch_save (pch_outfile);
+
+  timevar_push (TV_PCH_CPP_SAVE);
   cpp_write_pch_state (parse_in, pch_outfile);
+  timevar_pop (TV_PCH_CPP_SAVE);
 
   if (fseek (pch_outfile, 0, SEEK_SET) != 0
       || fwrite (get_ident (), IDENT_LENGTH, 1, pch_outfile) != 1)
     fatal_error ("can%'t write %s: %m", pch_file);
 
   fclose (pch_outfile);
+
+  timevar_pop (TV_PCH_SAVE);
 }
 
 /* Check the PCH file called NAME, open on FD, to see if it can be
@@ -243,8 +252,9 @@ c_common_valid_pch (cpp_reader *pfile, const char *name, int fd)
     fatal_error ("can%'t read %s: %m", name);
   else if (sizeread != IDENT_LENGTH + 16)
     {
-      cpp_error (pfile, CPP_DL_WARNING, "%s: too short to be a PCH file",
-                name);
+      if (cpp_get_options (pfile)->warn_invalid_pch)
+       cpp_error (pfile, CPP_DL_WARNING, "%s: too short to be a PCH file",
+                  name);
       return 2;
     }
 
@@ -366,12 +376,17 @@ c_common_read_pch (cpp_reader *pfile, const char *name,
   FILE *f;
   struct c_pch_header h;
   struct save_macro_data *smd;
+  expanded_location saved_loc;
+  bool saved_trace_includes;
+
+  timevar_push (TV_PCH_RESTORE);
 
   f = fdopen (fd, "rb");
   if (f == NULL)
     {
       cpp_errno (pfile, CPP_DL_ERROR, "calling fdopen");
-      return;
+      close (fd);
+      goto end;
     }
 
   cpp_get_callbacks (parse_in)->valid_pch = NULL;
@@ -379,7 +394,8 @@ c_common_read_pch (cpp_reader *pfile, const char *name,
   if (fread (&h, sizeof (h), 1, f) != 1)
     {
       cpp_errno (pfile, CPP_DL_ERROR, "reading");
-      return;
+      fclose (f);
+      goto end;
     }
 
   if (!flag_preprocess_only)
@@ -407,19 +423,39 @@ c_common_read_pch (cpp_reader *pfile, const char *name,
        cpp_errno (pfile, CPP_DL_ERROR, "seeking");
     }
 
+  /* Save the location and then restore it after reading the PCH.  */
+  saved_loc = expand_location (line_table->highest_line);
+  saved_trace_includes = line_table->trace_includes;
+
+  timevar_push (TV_PCH_CPP_RESTORE);
   cpp_prepare_state (pfile, &smd);
+  timevar_pop (TV_PCH_CPP_RESTORE);
 
   gt_pch_restore (f);
 
+  timevar_push (TV_PCH_CPP_RESTORE);
   if (cpp_read_state (pfile, name, f, smd) != 0)
-    return;
+    {
+      fclose (f);
+      timevar_pop (TV_PCH_CPP_RESTORE);
+      goto end;
+    }
+  timevar_pop (TV_PCH_CPP_RESTORE);
+
 
   fclose (f);
 
+  line_table->trace_includes = saved_trace_includes;
+  cpp_set_line_map (pfile, line_table);
+  linemap_add (line_table, LC_RENAME, 0, saved_loc.file, saved_loc.line);
+
   /* Give the front end a chance to take action after a PCH file has
      been loaded.  */
   if (lang_post_pch_load)
     (*lang_post_pch_load) ();
+
+end:
+  timevar_pop (TV_PCH_RESTORE);
 }
 
 /* Indicate that no more PCH files should be read.  */
@@ -448,7 +484,7 @@ c_common_pch_pragma (cpp_reader *pfile, const char *name)
   if (!cpp_get_options (pfile)->preprocessed)
     {
       error ("pch_preprocess pragma should only be used with -fpreprocessed");
-      inform ("use #include instead");
+      inform (input_location, "use #include instead");
       return;
     }
 
@@ -459,7 +495,7 @@ c_common_pch_pragma (cpp_reader *pfile, const char *name)
   if (c_common_valid_pch (pfile, name, fd) != 1)
     {
       if (!cpp_get_options (pfile)->warn_invalid_pch)
-       inform ("use -Winvalid-pch for more information");
+       inform (input_location, "use -Winvalid-pch for more information");
       fatal_error ("%s: PCH file was invalid", name);
     }