]> git.ipfire.org Git - thirdparty/gcc.git/commit
c-family: Fix ICE with large column number after restoring a PCH [PR105608]
authorLewis Hyatt <lhyatt@gmail.com>
Tue, 5 Dec 2023 16:33:39 +0000 (11:33 -0500)
committerLewis Hyatt <lhyatt@gmail.com>
Sat, 27 Jan 2024 12:56:37 +0000 (07:56 -0500)
commite8e584a81817713f98f16b2c81426905748237e3
treeb0505582327aa3a70c7ec714dda2fbfb8d599c88
parentf5f6d26550af46e31d97fd15afc4bc9d87a0a7d6
c-family: Fix ICE with large column number after restoring a PCH [PR105608]

Users are allowed to define macros prior to restoring a precompiled header
file, as long as those macros are not defined (or are defined identically)
in the PCH.  However, the PCH restoration process destroys all the macro
definitions, so libcpp has to record them before restoring the PCH and then
redefine them afterward.

This process does not currently assign great locations to the macros after
redefining them. Some work is needed to also remember the original locations
and get the line_maps instance in the right state (since, like all other
data structures, the line_maps instance is also reset after restoring a PCH).

This patch addresses a more pressing issue, which is that we ICE in some
cases since GCC 11, hitting an assert in line-maps.cc. It happens if the
first line encountered after the PCH restore requires an LC_RENAME map, such
as will happen if the line is sufficiently long.  This is much easier to
fix, since we just need to call linemap_line_start before asking libcpp to
redefine the stored macros, instead of afterward, to avoid the unexpected
need for an LC_RENAME before an LC_ENTER has been seen.

gcc/c-family/ChangeLog:

PR preprocessor/105608
* c-pch.cc (c_common_read_pch): Start a new line map before asking
libcpp to restore macros defined prior to reading the PCH, instead
of afterward.

gcc/testsuite/ChangeLog:

PR preprocessor/105608
* g++.dg/pch/line-map-1.C: New test.
* g++.dg/pch/line-map-1.Hs: New test.
* g++.dg/pch/line-map-2.C: New test.
* g++.dg/pch/line-map-2.Hs: New test.
gcc/c-family/c-pch.cc
gcc/testsuite/g++.dg/pch/line-map-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/pch/line-map-1.Hs [new file with mode: 0644]
gcc/testsuite/g++.dg/pch/line-map-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/pch/line-map-2.Hs [new file with mode: 0644]
gcc/testsuite/g++.dg/pch/line-map-3.Hs [new file with mode: 0644]