diff options
author | Lewis Hyatt <lhyatt@gmail.com> | 2024-01-31 15:50:11 -0500 |
---|---|---|
committer | Lewis Hyatt <lhyatt@gmail.com> | 2024-02-01 09:07:17 -0500 |
commit | 019dc63819befb2b82077fb2d76b5dd670946f36 (patch) | |
tree | 72bed730bc3affe6453dff6d5cb02f1e45fbd741 /libcpp | |
parent | 65b105b4f399559685200e1598ead8c7d0935c04 (diff) | |
download | gcc-019dc63819befb2b82077fb2d76b5dd670946f36.zip gcc-019dc63819befb2b82077fb2d76b5dd670946f36.tar.gz gcc-019dc63819befb2b82077fb2d76b5dd670946f36.tar.bz2 |
libcpp: Stabilize the location for macros restored after PCH load [PR105608]
libcpp currently lacks the infrastructure to assign correct locations to
macros that were defined prior to loading a PCH and then restored
afterwards. While I plan to address that fully for GCC 15, this patch
improves things by using at least a valid location, even if it's not the
best one. Without this change, libcpp uses pfile->directive_line as the
location for the restored macros, but this location_t applies to the old
line map, not the one that was just restored from the PCH, so the resulting
location is unpredictable and depends on what was stored in the line maps
before. With this change, all restored macros get assigned locations at the
line of the #include that triggered the PCH restore. A future patch will
store the actual file name and line number of each definition and then
synthesize locations in the new line map pointing to the right place.
gcc/c-family/ChangeLog:
PR preprocessor/105608
* c-pch.cc (c_common_read_pch): Adjust line map so that libcpp
assigns a location to restored macros which is the same location
that triggered the PCH include.
libcpp/ChangeLog:
PR preprocessor/105608
* pch.cc (cpp_read_state): Set a valid location for restored
macros.
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/pch.cc | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libcpp/pch.cc b/libcpp/pch.cc index e156fe2..f2f74ed 100644 --- a/libcpp/pch.cc +++ b/libcpp/pch.cc @@ -838,7 +838,14 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f, != 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); } |