aboutsummaryrefslogtreecommitdiff
path: root/gcc/cppfiles.c
diff options
context:
space:
mode:
authorPer Bothner <per@bothner.com>2004-02-18 14:02:39 -0800
committerPer Bothner <bothner@gcc.gnu.org>2004-02-18 14:02:39 -0800
commit22234f56d2395ae470961d3eb5fdc65a7597af9a (patch)
treee807c23671fa4dd53228ec168fcfa7e99628f896 /gcc/cppfiles.c
parent5a6d9a81c7415f0efb61a18f5bd4890286a1c003 (diff)
downloadgcc-22234f56d2395ae470961d3eb5fdc65a7597af9a.zip
gcc-22234f56d2395ae470961d3eb5fdc65a7597af9a.tar.gz
gcc-22234f56d2395ae470961d3eb5fdc65a7597af9a.tar.bz2
re PR preprocessor/14103 (ICEs on "gcc -E -imacros foo.h baz.c")
* cpphash.h (struct cpp_buffer): Restore return_at_eof field. This partly reverts my 2003-10-01 change, because we're back to logically including <command line> inside the main line. * cpplex.c (_cpp_get_fresh_line): Check return_at_eof field. * cppmacro.c (cpp_scan_nooutput): Set return_at_eof of current buffer. Fixes PR preprocessor/14103. * cppfiles.c (_cpp_stack_include): When appropriate decrement line_table's highest_location, fixing LAST_SOURCE_LINE_LOCATION. (cpp_push_include): Don't need to increment pfile's line field. * line-map.h (LAST_SOURCE_LINE_LOCATION): Only decrement by 1. * c-ppoutput.c (print struct): New first_time field. (init_pp_output): Set print.first_time. (pp_file_change): Use print.first_time, rather than MAIN_FILE_P, which is set also for (say) <command line>. Clear print.first_time. * cppfiles.c (struct _cpp_file): Comment and type for pch field does not match the code, so fix both. (should_stack_file): Inline include_pch_p function. (include_pch_p): Remove pointless function. * cpphash.h (struct cpp_buffer): Remove unused search_cached field. From-SVN: r78049
Diffstat (limited to 'gcc/cppfiles.c')
-rw-r--r--gcc/cppfiles.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index 862be9f..3a42e78 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -109,11 +109,8 @@ struct _cpp_file
/* If BUFFER above contains the true contents of the file. */
bool buffer_valid;
- /* 0: file not known to be a PCH.
- 1: file is a PCH (on return from find_include_file).
- 2: file is not and never will be a valid precompiled header.
- 3: file is always a valid precompiled header. */
- uchar pch;
+ /* File is a PCH (on return from find_include_file). */
+ bool pch;
};
/* A singly-linked list for all searches for a given file name, with
@@ -180,7 +177,6 @@ static void read_name_map (cpp_dir *dir);
static char *remap_filename (cpp_reader *pfile, _cpp_file *file);
static char *append_file_to_dir (const char *fname, cpp_dir *dir);
static bool validate_pch (cpp_reader *, _cpp_file *file, const char *pchname);
-static bool include_pch_p (_cpp_file *file);
static int pchf_adder (void **slot, void *data);
static int pchf_save_compare (const void *e1, const void *e2);
static int pchf_compare (const void *d_p, const void *e_p);
@@ -577,7 +573,7 @@ should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import)
return false;
/* Handle PCH files immediately; don't stack them. */
- if (include_pch_p (file))
+ if (file->pch)
{
pfile->cb.read_pch (pfile, file->path, file->fd, file->pchname);
close (file->fd);
@@ -747,13 +743,25 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
enum include_type type)
{
struct cpp_dir *dir;
+ _cpp_file *file;
dir = search_path_head (pfile, fname, angle_brackets, type);
if (!dir)
return false;
- return _cpp_stack_file (pfile, _cpp_find_file (pfile, fname, dir, false),
- type == IT_IMPORT);
+ file = _cpp_find_file (pfile, fname, dir, false);
+
+ /* Compensate for the increment in linemap_add. In the case of a
+ normal #include, we're currently at the start of the line
+ *following* the #include. A separate source_location for this
+ location makes no sense (until we do the LC_LEAVE), and
+ complicates LAST_SOURCE_LINE_LOCATION. This does not apply if we
+ found a PCH file (in which case linemap_add is not called) or we
+ were included from the command-line. */
+ if (! file->pch && file->err_no == 0 && type != IT_CMDLINE)
+ pfile->line_table->highest_location--;
+
+ return _cpp_stack_file (pfile, file, type == IT_IMPORT);
}
/* Could not open FILE. The complication is dependency output. */
@@ -1032,8 +1040,6 @@ _cpp_compare_file_date (cpp_reader *pfile, const char *fname,
bool
cpp_push_include (cpp_reader *pfile, const char *fname)
{
- /* Make the command line directive take up a line. */
- pfile->line++;
return _cpp_stack_include (pfile, fname, false, IT_CMDLINE);
}
@@ -1228,13 +1234,6 @@ remap_filename (cpp_reader *pfile, _cpp_file *file)
}
}
-/* Return true if FILE is usable by PCH. */
-static bool
-include_pch_p (_cpp_file *file)
-{
- return file->pch & 1;
-}
-
/* Returns true if PCHNAME is a valid PCH file for FILE. */
static bool
validate_pch (cpp_reader *pfile, _cpp_file *file, const char *pchname)