diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-09-18 18:28:45 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-09-18 18:28:45 +0000 |
commit | 58a73f6da5d0ed7dc1b04cbfb90c0205a3c50e3f (patch) | |
tree | 41687c822ea825dcc079e7f471d9ec806d311374 /libcpp | |
parent | 281de4253d972d89f21b2bc3ef4050f88e3fcf3c (diff) | |
parent | ba7c8cb5715a162ac41ca5241628e7e02ecd217f (diff) | |
download | gcc-58a73f6da5d0ed7dc1b04cbfb90c0205a3c50e3f.zip gcc-58a73f6da5d0ed7dc1b04cbfb90c0205a3c50e3f.tar.gz gcc-58a73f6da5d0ed7dc1b04cbfb90c0205a3c50e3f.tar.bz2 |
Merge from trunk revision 275890.
From-SVN: r275900
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 47 | ||||
-rw-r--r-- | libcpp/directives-only.c | 2 | ||||
-rw-r--r-- | libcpp/directives.c | 35 | ||||
-rw-r--r-- | libcpp/expr.c | 4 | ||||
-rw-r--r-- | libcpp/files.c | 298 | ||||
-rw-r--r-- | libcpp/init.c | 2 | ||||
-rw-r--r-- | libcpp/internal.h | 36 | ||||
-rw-r--r-- | libcpp/lex.c | 8 | ||||
-rw-r--r-- | libcpp/line-map.c | 6 |
9 files changed, 253 insertions, 185 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index c6e8e04..1ec8541 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,50 @@ +2019-08-30 Nathan Sidwell <nathan@acm.org> + + New # semantics for popping to "" name. + libcpp/ + * directives.c (do_linemarker): Popping to "" name means get the + name from the include stack.. + +2019-09-05 Nathan Sidwell <nathan@acm.org> + + PR preprocessor/91639 + * directives.c (do_include_common): Tell lexer we're a #include. + * files.c (_cpp_stack_file): Lexer will have always incremented. + * internal.h (struct cpp_context): Extend in_directive's + semantics. + * lex.c (_cpp_lex_direct): Increment line for final \n when lexing + for an ISO #include. + * line-map.c (linemap_line_start): Remember if we overflowed. + +2019-09-03 Ulrich Weigand <uweigand@de.ibm.com> + + * directives.c: Remove references to spu from comments. + * expr.c: Likewise. + +2019-08-29 Nathan Sidwell <nathan@acm.org> + + * internal.h (enum include_type): Add IT_MAIN, IT_DIRECTIVE_HWM, + IT_HEADER_HWM. + (_cpp_stack_file): Take include_type, not a bool. + * files.c (_cpp_find_file): Refactor to not hide an if inside a + for conditional. + (should_stack_file): Break apart to ... + (is_known_idempotent_file, has_unique_contents): ... these. + (_cpp_stack_file): Replace IMPORT boolean with include_type enum. + Refactor to use new predicates. Do linemap compensation here ... + (_cpp_stack_include): ... not here. + * init.c (cpp_read_main_file): Pass IT_MAIN to _cpp_stack_file. + +2019-08-28 Nathan Sidwell <nathan@acm.org> + + * directives-only.c (_cpp_preprocess_dir_only): Use false, not + zero for _cpp_handle_directive call. + * directives.c (_cpp_handle_directive): Indented is bool. + * files.c (struct _cpp_file): Make bools 1 bit bitfields. + * internal.h (enum include_type): Reformat and comment. + (struct cpp_buffer): Make flags 1 bit bitfields. + (_cpp_handle_directive): Indented is bool. + 2019-07-09 Martin Sebor <msebor@redhat.com> * include/line-map.h: Change class-key from class to struct and vice diff --git a/libcpp/directives-only.c b/libcpp/directives-only.c index 847225a..fae3b5b 100644 --- a/libcpp/directives-only.c +++ b/libcpp/directives-only.c @@ -101,7 +101,7 @@ _cpp_preprocess_dir_only (cpp_reader *pfile, /* Ensure proper column numbering for generated error messages. */ buffer->line_base -= col - 1; - _cpp_handle_directive (pfile, 0 /* ignore indented */); + _cpp_handle_directive (pfile, false /* ignore indented */); /* Sanitize the line settings. Duplicate #include's can mess things up. */ diff --git a/libcpp/directives.c b/libcpp/directives.c index ddf8979..61f1fef 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -406,13 +406,13 @@ directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented) } } -/* Check if we have a known directive. INDENTED is nonzero if the +/* Check if we have a known directive. INDENTED is true if the '#' of the directive was indented. This function is in this file to save unnecessarily exporting dtable etc. to lex.c. Returns nonzero if the line of tokens has been handled, zero if we should continue processing the line. */ int -_cpp_handle_directive (cpp_reader *pfile, int indented) +_cpp_handle_directive (cpp_reader *pfile, bool indented) { const directive *dir = 0; const cpp_token *dname; @@ -818,6 +818,10 @@ do_include_common (cpp_reader *pfile, enum include_type type) callback can dump comments which follow #include. */ pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); + /* Tell the lexer this is an include directive -- we want it to + increment the line number even if this is the last line of a file. */ + pfile->state.in_directive = 2; + fname = parse_include (pfile, &angle_brackets, &buf, &location); if (!fname) goto done; @@ -1084,9 +1088,17 @@ do_linemarker (cpp_reader *pfile) map = LINEMAPS_LAST_ORDINARY_MAP (line_table); const line_map_ordinary *from = linemap_included_from_linemap (line_table, map); - if (MAIN_FILE_P (map) - || (from - && filename_cmp (ORDINARY_MAP_FILE_NAME (from), new_file) != 0)) + + if (!from) + /* Not nested. */; + else if (!new_file[0]) + /* Leaving to "" means fill in the popped-to name. */ + new_file = ORDINARY_MAP_FILE_NAME (from); + else if (filename_cmp (ORDINARY_MAP_FILE_NAME (from), new_file) != 0) + /* It's the wrong name, Grommit! */ + from = NULL; + + if (!from) { cpp_warning (pfile, CPP_W_NONE, "file \"%s\" linemarker ignored due to " @@ -1094,6 +1106,7 @@ do_linemarker (cpp_reader *pfile) return; } } + /* Compensate for the increment in linemap_add that occurs in _cpp_do_file_change. We're currently at the start of the line *following* the #line directive. A separate location_t for this @@ -1952,9 +1965,9 @@ do_ifdef (cpp_reader *pfile) if (node) { /* Do not treat conditional macros as being defined. This is due to - the powerpc and spu ports using conditional macros for 'vector', - 'bool', and 'pixel' to act as conditional keywords. This messes - up tests like #ifndef bool. */ + the powerpc port using conditional macros for 'vector', 'bool', + and 'pixel' to act as conditional keywords. This messes up tests + like #ifndef bool. */ skip = !cpp_macro_p (node) || (node->flags & NODE_CONDITIONAL); _cpp_mark_macro_used (node); _cpp_maybe_notify_macro_use (pfile, node); @@ -1981,9 +1994,9 @@ do_ifndef (cpp_reader *pfile) if (node) { /* Do not treat conditional macros as being defined. This is due to - the powerpc and spu ports using conditional macros for 'vector', - 'bool', and 'pixel' to act as conditional keywords. This messes - up tests like #ifndef bool. */ + the powerpc port using conditional macros for 'vector', 'bool', + and 'pixel' to act as conditional keywords. This messes up tests + like #ifndef bool. */ skip = (cpp_macro_p (node) && !(node->flags & NODE_CONDITIONAL)); _cpp_mark_macro_used (node); diff --git a/libcpp/expr.c b/libcpp/expr.c index d8438a5..4b514b1 100644 --- a/libcpp/expr.c +++ b/libcpp/expr.c @@ -1075,8 +1075,8 @@ parse_defined (cpp_reader *pfile) pfile->state.prevent_expansion--; /* Do not treat conditional macros as being defined. This is due to the - powerpc and spu ports using conditional macros for 'vector', 'bool', and - 'pixel' to act as conditional keywords. This messes up tests like #ifndef + powerpc port using conditional macros for 'vector', 'bool', and 'pixel' + to act as conditional keywords. This messes up tests like #ifndef bool. */ result.unsignedp = false; result.high = 0; diff --git a/libcpp/files.c b/libcpp/files.c index 6ef6d07..aa77dc7 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -98,19 +98,19 @@ struct _cpp_file unsigned short stack_count; /* If opened with #import or contains #pragma once. */ - bool once_only; + bool once_only : 1; /* If read() failed before. */ - bool dont_read; + bool dont_read : 1; /* If this file is the main file. */ - bool main_file; + bool main_file : 1; /* If BUFFER above contains the true contents of the file. */ - bool buffer_valid; + bool buffer_valid : 1; /* If this file is implicitly preincluded. */ - bool implicit_preinclude; + bool implicit_preinclude : 1; }; /* A singly-linked list for all searches for a given file name, with @@ -176,8 +176,6 @@ static bool read_file_guts (cpp_reader *pfile, _cpp_file *file, location_t loc); static bool read_file (cpp_reader *pfile, _cpp_file *file, location_t loc); -static bool should_stack_file (cpp_reader *, _cpp_file *file, bool import, - location_t loc); static struct cpp_dir *search_path_head (cpp_reader *, const char *fname, int angle_brackets, enum include_type); static const char *dir_name_of_file (_cpp_file *file); @@ -536,79 +534,86 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, || (pfile->buffer && pfile->buffer->file->implicit_preinclude)); - /* Try each path in the include chain. */ - for (; !fake ;) - { - if (find_file_in_dir (pfile, file, &invalid_pch, loc)) - break; - - file->dir = file->dir->next; - if (file->dir == NULL) - { - if (search_path_exhausted (pfile, fname, file)) - { - /* Although this file must not go in the cache, because - the file found might depend on things (like the current file) - that aren't represented in the cache, it still has to go in - the list of all files so that #import works. */ - file->next_file = pfile->all_files; - pfile->all_files = file; - if (*hash_slot == NULL) - { - /* If *hash_slot is NULL, the above htab_find_slot_with_hash - call just created the slot, but we aren't going to store - there anything, so need to remove the newly created entry. - htab_clear_slot requires that it is non-NULL, so store - there some non-NULL pointer, htab_clear_slot will - overwrite it immediately. */ - *hash_slot = file; - htab_clear_slot (pfile->file_hash, hash_slot); - } - return file; - } - - if (invalid_pch) - { - cpp_error (pfile, CPP_DL_ERROR, - "one or more PCH files were found, but they were invalid"); - if (!cpp_get_options (pfile)->warn_invalid_pch) - cpp_error (pfile, CPP_DL_ERROR, - "use -Winvalid-pch for more information"); - } - if (implicit_preinclude) - { - free ((char *) file->name); - free (file); - if (*hash_slot == NULL) - { - /* See comment on the above htab_clear_slot call. */ - *hash_slot = file; - htab_clear_slot (pfile->file_hash, hash_slot); - } - return NULL; - } - else - open_file_failed (pfile, file, angle_brackets, loc); + if (!fake) + /* Try each path in the include chain. */ + for (;;) + { + if (find_file_in_dir (pfile, file, &invalid_pch, loc)) break; - } - /* Only check the cache for the starting location (done above) - and the quote and bracket chain heads because there are no - other possible starting points for searches. */ - if (file->dir == pfile->bracket_include) - saw_bracket_include = true; - else if (file->dir == pfile->quote_include) - saw_quote_include = true; - else - continue; + file->dir = file->dir->next; + if (file->dir == NULL) + { + if (search_path_exhausted (pfile, fname, file)) + { + /* Although this file must not go in the cache, + because the file found might depend on things (like + the current file) that aren't represented in the + cache, it still has to go in the list of all files + so that #import works. */ + file->next_file = pfile->all_files; + pfile->all_files = file; + if (*hash_slot == NULL) + { + /* If *hash_slot is NULL, the above + htab_find_slot_with_hash call just created the + slot, but we aren't going to store there + anything, so need to remove the newly created + entry. htab_clear_slot requires that it is + non-NULL, so store there some non-NULL pointer, + htab_clear_slot will overwrite it + immediately. */ + *hash_slot = file; + htab_clear_slot (pfile->file_hash, hash_slot); + } + return file; + } + + if (invalid_pch) + { + cpp_error (pfile, CPP_DL_ERROR, + "one or more PCH files were found," + " but they were invalid"); + if (!cpp_get_options (pfile)->warn_invalid_pch) + cpp_error (pfile, CPP_DL_ERROR, + "use -Winvalid-pch for more information"); + } + + if (implicit_preinclude) + { + free ((char *) file->name); + free (file); + if (*hash_slot == NULL) + { + /* See comment on the above htab_clear_slot call. */ + *hash_slot = file; + htab_clear_slot (pfile->file_hash, hash_slot); + } + return NULL; + } - entry = search_cache ((struct cpp_file_hash_entry *) *hash_slot, file->dir); - if (entry) - { - found_in_cache = file->dir; - break; - } - } + open_file_failed (pfile, file, angle_brackets, loc); + break; + } + + /* Only check the cache for the starting location (done above) + and the quote and bracket chain heads because there are no + other possible starting points for searches. */ + if (file->dir == pfile->bracket_include) + saw_bracket_include = true; + else if (file->dir == pfile->quote_include) + saw_quote_include = true; + else + continue; + + entry + = search_cache ((struct cpp_file_hash_entry *) *hash_slot, file->dir); + if (entry) + { + found_in_cache = file->dir; + break; + } + } if (entry) { @@ -778,18 +783,14 @@ read_file (cpp_reader *pfile, _cpp_file *file, location_t loc) return !file->dont_read; } -/* Returns TRUE if FILE's contents have been successfully placed in - FILE->buffer and the file should be stacked, otherwise false. - Use LOC for any diagnostics. */ +/* Returns TRUE if FILE is already known to be idempotent, and should + therefore not be read again. */ static bool -should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import, - location_t loc) +is_known_idempotent_file (cpp_reader *pfile, _cpp_file *file, bool import) { - _cpp_file *f; - /* Skip once-only files. */ if (file->once_only) - return false; + return true; /* We must mark the file once-only if #import now, before header guard checks. Otherwise, undefining the header guard might @@ -800,13 +801,13 @@ should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import, /* Don't stack files that have been stacked before. */ if (file->stack_count) - return false; + return true; } /* Skip if the file had a header guard and the macro is defined. PCH relies on this appearing before the PCH handler below. */ if (file->cmacro && cpp_macro_p (file->cmacro)) - return false; + return true; /* Handle PCH files immediately; don't stack them. */ if (file->pchname) @@ -815,12 +816,19 @@ should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import, file->fd = -1; free ((void *) file->pchname); file->pchname = NULL; - return false; + return true; } - if (!read_file (pfile, file, loc)) - return false; + return false; +} +/* Return TRUE if file has unique contents, so we should read process + it. The file's contents must already have been read. */ + +static bool +has_unique_contents (cpp_reader *pfile, _cpp_file *file, bool import, + location_t loc) +{ /* Check the file against the PCH file. This is done before checking against files we've already seen, since it may save on I/O. */ @@ -841,10 +849,10 @@ should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import, /* We may have read the file under a different name. Look for likely candidates and compare file contents to be sure. */ - for (f = pfile->all_files; f; f = f->next_file) + for (_cpp_file *f = pfile->all_files; f; f = f->next_file) { if (f == file) - continue; + continue; /* It'sa me! */ if ((import || f->once_only) && f->err_no == 0 @@ -852,7 +860,6 @@ should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import, && f->st.st_size == file->st.st_size) { _cpp_file *ref_file; - bool same_file_p = false; if (f->buffer && !f->buffer_valid) { @@ -865,12 +872,11 @@ should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import, /* The file is not stacked anymore. We can reuse it. */ ref_file = f; - same_file_p = read_file (pfile, ref_file, loc) - /* Size might have changed in read_file(). */ - && ref_file->st.st_size == file->st.st_size - && !memcmp (ref_file->buffer, - file->buffer, - file->st.st_size); + bool same_file_p = (read_file (pfile, ref_file, loc) + /* Size might have changed in read_file(). */ + && ref_file->st.st_size == file->st.st_size + && !memcmp (ref_file->buffer, file->buffer, + file->st.st_size)); if (f->buffer && !f->buffer_valid) { @@ -879,11 +885,12 @@ should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import, } if (same_file_p) - break; + /* Already seen under a different name. */ + return false; } } - return f == NULL; + return true; } /* Place the file referenced by FILE into a new buffer on the buffer @@ -891,25 +898,27 @@ should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import, because of a #import directive. Returns true if a buffer is stacked. Use LOC for any diagnostics. */ bool -_cpp_stack_file (cpp_reader *pfile, _cpp_file *file, bool import, +_cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type, location_t loc) { - cpp_buffer *buffer; - int sysp; + if (is_known_idempotent_file (pfile, file, type == IT_IMPORT)) + return false; - if (!should_stack_file (pfile, file, import, loc)) + if (!read_file (pfile, file, loc)) return false; - if (pfile->buffer == NULL || file->dir == NULL) - sysp = 0; - else - sysp = MAX (pfile->buffer->sysp, file->dir->sysp); + if (!has_unique_contents (pfile, file, type == IT_IMPORT, loc)) + return false; + + int sysp = 0; + if (pfile->buffer && file->dir) + sysp = MAX (pfile->buffer->sysp, file->dir->sysp); /* Add the file to the dependencies on its first inclusion. */ - if (!file->stack_count - && CPP_OPTION (pfile, deps.style) > !!sysp + if (CPP_OPTION (pfile, deps.style) > (sysp != 0) + && !file->stack_count && file->path[0] - && (!file->main_file || !CPP_OPTION (pfile, deps.ignore_main_file))) + && !(file->main_file && CPP_OPTION (pfile, deps.ignore_main_file))) deps_add_dep (pfile->deps, file->path); /* Clear buffer_valid since _cpp_clean_line messes it up. */ @@ -917,9 +926,10 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, bool import, file->stack_count++; /* Stack the buffer. */ - buffer = cpp_push_buffer (pfile, file->buffer, file->st.st_size, - CPP_OPTION (pfile, preprocessed) - && !CPP_OPTION (pfile, directives_only)); + cpp_buffer *buffer + = cpp_push_buffer (pfile, file->buffer, file->st.st_size, + CPP_OPTION (pfile, preprocessed) + && !CPP_OPTION (pfile, directives_only)); buffer->file = file; buffer->sysp = sysp; buffer->to_free = file->buffer_start; @@ -928,7 +938,18 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, bool import, pfile->mi_valid = true; pfile->mi_cmacro = 0; - /* Generate the call back. */ + /* In the case of a normal #include, we're now at the start of the + line *following* the #include. A separate location_t for this + location makes no sense, until we do the LC_LEAVE. + + This does not apply if we found a PCH file, we're not a regular + include, or we ran out of locations. */ + if (file->pchname == NULL + && type < IT_DIRECTIVE_HWM + && pfile->line_table->highest_location != LINE_MAP_MAX_LOCATION - 1) + pfile->line_table->highest_location--; + + /* Add line map and do callbacks. */ _cpp_do_file_change (pfile, LC_ENTER, file->path, 1, sysp); return true; @@ -1009,11 +1030,6 @@ bool _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets, enum include_type type, location_t loc) { - struct cpp_dir *dir; - _cpp_file *file; - bool stacked; - bool decremented = false; - /* For -include command-line flags we have type == IT_CMDLINE. When the first -include file is processed we have the case, where pfile->cur_token == pfile->cur_run->base, we are directly called up @@ -1026,48 +1042,16 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets, if (type == IT_CMDLINE && pfile->cur_token != pfile->cur_run->base) pfile->cur_token[-1].src_loc = 0; - dir = search_path_head (pfile, fname, angle_brackets, type); + cpp_dir *dir = search_path_head (pfile, fname, angle_brackets, type); if (!dir) return false; - file = _cpp_find_file (pfile, fname, dir, false, angle_brackets, - type == IT_DEFAULT, loc); + _cpp_file *file = _cpp_find_file (pfile, fname, dir, false, angle_brackets, + type == IT_DEFAULT, loc); if (type == IT_DEFAULT && file == NULL) return false; - /* Compensate for the increment in linemap_add that occurs if - _cpp_stack_file actually stacks the file. In the case of a normal - #include, we're currently at the start of the line *following* the - #include. A separate location_t 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. In the case that the #include is the last - line in the file, highest_location still points to the current - line, not the start of the next line, so we do not decrement in - this case. See plugin/location-overflow-test-pr83173.h for an - example. */ - if (file->pchname == NULL && file->err_no == 0 - && type != IT_CMDLINE && type != IT_DEFAULT) - { - int highest_line = linemap_get_expansion_line (pfile->line_table, - pfile->line_table->highest_location); - int source_line = linemap_get_expansion_line (pfile->line_table, loc); - if (highest_line > source_line) - { - pfile->line_table->highest_location--; - decremented = true; - } - } - - stacked = _cpp_stack_file (pfile, file, type == IT_IMPORT, loc); - - if (decremented && !stacked) - /* _cpp_stack_file didn't stack the file, so let's rollback the - compensation dance we performed above. */ - pfile->line_table->highest_location++; - - return stacked; + return _cpp_stack_file (pfile, file, type, loc); } /* Could not open FILE. The complication is dependency output. */ diff --git a/libcpp/init.c b/libcpp/init.c index 472f104..ccbfc96 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -651,7 +651,7 @@ cpp_read_main_file (cpp_reader *pfile, const char *fname) if (_cpp_find_failed (pfile->main_file)) return NULL; - _cpp_stack_file (pfile, pfile->main_file, false, loc); + _cpp_stack_file (pfile, pfile->main_file, IT_MAIN, 0); /* For foo.i, read the original filename foo.c now, for the benefit of the front ends. */ diff --git a/libcpp/internal.h b/libcpp/internal.h index 45167a9..f9bcd37 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -113,7 +113,21 @@ extern unsigned char *_cpp_unaligned_alloc (cpp_reader *, size_t); #define BUFF_LIMIT(BUFF) ((BUFF)->limit) /* #include types. */ -enum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_IMPORT, IT_CMDLINE, IT_DEFAULT}; +enum include_type + { + /* Directive-based including mechanisms. */ + IT_INCLUDE, /* #include */ + IT_INCLUDE_NEXT, /* #include_next */ + IT_IMPORT, /* #import */ + + /* Non-directive including mechanisms. */ + IT_CMDLINE, /* -include */ + IT_DEFAULT, /* forced header */ + IT_MAIN, /* main */ + + IT_DIRECTIVE_HWM = IT_IMPORT + 1, /* Directives below this. */ + IT_HEADER_HWM = IT_DEFAULT + 1, /* Header files below this. */ + }; union utoken { @@ -220,7 +234,8 @@ struct cpp_context struct lexer_state { - /* Nonzero if first token on line is CPP_HASH. */ + /* 1 if we're handling a directive. 2 if it's an include-like + directive. */ unsigned char in_directive; /* Nonzero if in a directive that will handle padding tokens itself. @@ -327,23 +342,23 @@ struct cpp_buffer struct if_stack *if_stack; /* True if we need to get the next clean line. */ - bool need_line; + bool need_line : 1; /* True if we have already warned about C++ comments in this file. The warning happens only for C89 extended mode with -pedantic on, or for -Wtraditional, and only once per file (otherwise it would be far too noisy). */ - unsigned int warned_cplusplus_comments : 1; + bool warned_cplusplus_comments : 1; /* True if we don't process trigraphs and escaped newlines. True for preprocessed input, command line directives, and _Pragma buffers. */ - unsigned int from_stage3 : 1; + bool from_stage3 : 1; /* At EOF, a buffer is automatically popped. If RETURN_AT_EOF is true, a CPP_EOF token is then returned. Otherwise, the next token from the enclosing buffer is returned. */ - unsigned int return_at_eof : 1; + bool return_at_eof : 1; /* One for a system header, two for a C system header file that therefore needs to be extern "C" protected in C++, and zero otherwise. */ @@ -419,13 +434,13 @@ struct cpp_reader /* This is the node representing the macro being expanded at top-level. The value of this data member is valid iff - in_macro_expansion_p() returns TRUE. */ + cpp_in_macro_expansion_p() returns TRUE. */ cpp_hashnode *top_most_macro_node; /* Nonzero if we are about to expand a macro. Note that if we are really expanding a macro, the function macro_of_context returns the macro being expanded and this flag is set to false. Client - code should use the function in_macro_expansion_p to know if we + code should use the function cpp_in_macro_expansion_p to know if we are either about to expand a macro, or are actually expanding one. */ bool about_to_expand_macro_p; @@ -661,8 +676,7 @@ extern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *, extern bool _cpp_find_failed (_cpp_file *); extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *); extern void _cpp_fake_include (cpp_reader *, const char *); -extern bool _cpp_stack_file (cpp_reader *, _cpp_file*, bool, - location_t); +extern bool _cpp_stack_file (cpp_reader *, _cpp_file*, include_type, location_t); extern bool _cpp_stack_include (cpp_reader *, const char *, int, enum include_type, location_t); extern int _cpp_compare_file_date (cpp_reader *, const char *, int); @@ -711,7 +725,7 @@ extern const char *cpp_named_operator2name (enum cpp_ttype type); /* In directives.c */ extern int _cpp_test_assertion (cpp_reader *, unsigned int *); -extern int _cpp_handle_directive (cpp_reader *, int); +extern int _cpp_handle_directive (cpp_reader *, bool); extern void _cpp_define_builtin (cpp_reader *, const char *); extern char ** _cpp_save_pragma_names (cpp_reader *); extern void _cpp_restore_pragma_names (cpp_reader *, char **); diff --git a/libcpp/lex.c b/libcpp/lex.c index 16ded6e..52e5bce 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -2771,7 +2771,13 @@ _cpp_lex_direct (cpp_reader *pfile) goto skipped_white; case '\n': - if (buffer->cur < buffer->rlimit) + /* Increment the line, unless this is the last line ... */ + if (buffer->cur < buffer->rlimit + /* ... or this is a #include, (where _cpp_stack_file needs to + unwind by one line) ... */ + || (pfile->state.in_directive > 1 + /* ... except traditional-cpp increments this elsewhere. */ + && !CPP_OPTION (pfile, traditional))) CPP_INCREMENT_LINE (pfile, 0); buffer->need_line = true; goto fresh_line; diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 572d7f4..d6924eb 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -764,7 +764,11 @@ linemap_line_start (line_maps *set, linenum_type to_line, /* Locations of ordinary tokens are always lower than locations of macro tokens. */ if (r >= LINE_MAP_MAX_LOCATION) - return 0; + { + /* Remember we overflowed. */ + set->highest_line = set->highest_location = LINE_MAP_MAX_LOCATION - 1; + return 0; + } set->highest_line = r; if (r > set->highest_location) |