struct save_macro_data *smd;
expanded_location saved_loc;
bool saved_trace_includes;
+ int cpp_result;
timevar_push (TV_PCH_RESTORE);
cpp_set_line_map (pfile, line_table);
rebuild_location_adhoc_htab (line_table);
line_table->trace_includes = saved_trace_includes;
- linemap_add (line_table, LC_ENTER, 0, saved_loc.file, saved_loc.line);
+
+ /* Set the current location to the line containing the #include (or the
+ #pragma GCC pch_preprocess) for the purpose of assigning locations to any
+ macros that are about to be restored. */
+ linemap_add (line_table, LC_ENTER, 0, saved_loc.file,
+ saved_loc.line > 1 ? saved_loc.line - 1 : saved_loc.line);
timevar_push (TV_PCH_CPP_RESTORE);
- if (cpp_read_state (pfile, name, f, smd) != 0)
- {
- fclose (f);
- timevar_pop (TV_PCH_CPP_RESTORE);
- goto end;
- }
- timevar_pop (TV_PCH_CPP_RESTORE);
+ cpp_result = cpp_read_state (pfile, name, f, smd);
+ /* Set the current location to the line following the #include, where we
+ were prior to processing the PCH. */
+ linemap_line_start (line_table, saved_loc.line, 0);
+ timevar_pop (TV_PCH_CPP_RESTORE);
fclose (f);
+ if (cpp_result != 0)
+ goto end;
+
/* Give the front end a chance to take action after a PCH file has
been loaded. */
if (lang_post_pch_load)
!= NULL)
{
_cpp_clean_line (r);
- if (!_cpp_create_definition (r, h, 0))
+
+ /* ??? Using r->line_table->highest_line is not ideal here, but we
+ do need to use some location that is relative to the new line
+ map just loaded, not the old one that was in effect when these
+ macros were lexed. The proper fix is to remember the file name
+ and line number where each macro was defined, and then add
+ these locations into the new line map. See PR105608. */
+ if (!_cpp_create_definition (r, h, r->line_table->highest_line))
abort ();
_cpp_pop_buffer (r);
}