On 11-08-22 07:10 , Dodji Seketeli wrote:
Hello,

In c_common_read_pch when gt_pch_restore loads a new pch, the previous
line table (referenced from the global 'line_table') is
garbage-collected and a new one is built.

As the global instance of cpp_reader referenced by the local variable
'pfile' has a pfile->line_table member that references the
'line_table' global, pfile->line_table needs to be set to the new
value of line_table after gt_pch_restore is called, otherwise
pfile->line_table points to garbage-collected memory.  This is what
the call to cpp_set_line_map in c_common_read_pch is for.

The problem is that cpp_set_line_map is called too late as
cpp_read_state (called before cpp_set_line_map) indirectly touches
some pfile->line_table dangling garbage-collected memory[1].

This doesn't cause any visible havoc in trunk yet but I am seeing it
crashing as I am fiddling with line map stuff on the side.

The two-liner patch below just calls cpp_set_line_map right after
gt_pch_restore to restore pfile->line_table before anyone touches it.

[1]: This happens via cpp_read_state ->  _cpp_create_definition ->
_cpp_create_iso_definition ->  _cpp_lex_token ->  _cpp_lex_direct ->
linemap_position_for_column.

Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.

OK for trunk?

gcc/

        * c-family/c-pch.c (c_common_read_pch): Re-set line table right
        after reading in the pch.

OK.


Diego.

Reply via email to