]> gcc.gnu.org Git - 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 04:27:53 +0000 (23:27 -0500)
commit5200ef26ac1771a75596394c20c5f1a348694d5e
treed5390d29891b3fe9c52ea0fddf324351570c95cc
parentce9dae56404cfcc94b5149e955d43431e4db470a
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]
This page took 0.058177 seconds and 6 git commands to generate.