]> 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 17:08:35 +0000 (12:08 -0500)
commit52029ef151cc9b1c90fa620079fc17f3960c467c
treee657a4e9f1f32eb01f494c2ff58112e53fba7af5
parent67e2ee75744dad83816753a159cebad4dd7a1e45
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).
The new testcase line-map-3.C contains XFAILed examples where the locations
are wrong.

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.
* g++.dg/pch/line-map-3.C: New test.
* g++.dg/pch/line-map-3.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.C [new file with mode: 0644]
gcc/testsuite/g++.dg/pch/line-map-3.Hs [new file with mode: 0644]