Skip to content
Snippets Groups Projects
  • Lewis Hyatt's avatar
    019dc638
    libcpp: Stabilize the location for macros restored after PCH load [PR105608] · 019dc638
    Lewis Hyatt authored
    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.
    019dc638
    History
    libcpp: Stabilize the location for macros restored after PCH load [PR105608]
    Lewis Hyatt authored
    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.
pch.cc 23.04 KiB