Skip to content
Snippets Groups Projects
Commit 518def14 authored by Jakub Jelinek's avatar Jakub Jelinek Committed by Jakub Jelinek
Browse files

input: Fix up ICEs with --param=file-cache-files=N for N > 16 [PR118860]

The following testcase ICEs, because we first construct file_cache object
inside of *global_dc, then process options and then call file_cache::tune.
The earlier construction allocates the m_file_slots array (using new)
based on the static data member file_cache::num_file_slots, but then tune
changes it, without actually reallocating all m_file_slots arrays in already
constructed file_cache objects.

I think it is just weird to have the count be a static data member and
the pointer be non-static data member, that is just asking for issues like
this.

So, this patch changes num_file_slots into m_num_file_slots and turns tune
into a non-static member function and changes toplev.cc to call it on the
global_gc->get_file_cache () object.  And let's the tune just delete the
array and allocate it freshly if there is a change in the number of slots
or lines.

Note, file_cache_slot has similar problem, but because there are many, I
haven't moved the count into those objects; I just hope that when tune
is called there is exactly one file_cache constructed and all the
file_cache_slot objects constructed are pointed by its m_file_slots member,
so also on lines change it just deletes it and allocates again.  I think
it should be unlikely that the cache actually has any used slots by the time
it is called.

2025-02-27  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/118860
	* input.h (file_cache::tune): No longer static.  Rename argument
	from num_file_slots_ to num_file_slots.  Formatting fix.
	(file_cache::num_file_slots): Renamed to ...
	(file_cache::m_num_file_slots): ... this.  No longer static.
	* input.cc (file_cache_slot::tune): Change return type from void to
	size_t, return previous file_cache_slot::line_record_size value.
	Formatting fixes.
	(file_cache::tune): Rename argument from num_file_slots_ to
	num_file_slots.  Set m_num_file_slots rather than num_file_slots.
	If m_num_file_slots or file_cache_slot::line_record_size changes,
	delete[] m_file_slots and new it again.
	(file_cache::num_file_slots): Remove definition.
	(file_cache::lookup_file): Use m_num_file_slots rather than
	num_file_slots.
	(file_cache::evicted_cache_tab_entry): Likewise.
	(file_cache::file_cache): Likewise.  Initialize m_num_file_slots
	to 16.
	(file_cache::dump): Use m_num_file_slots rather than num_file_slots.
	(file_cache_slot::get_next_line): Formatting fixes.
	(file_cache_slot::read_line_num): Likewise.
	(get_source_text_between): Likewise.
	* toplev.cc (toplev::main): Call global_dc->get_file_cache ().tune
	rather than file_cache::tune.

	* gcc.dg/pr118860.c: New test.
parent e333ad4e
No related branches found
Tags releases/gcc-13.1.0
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment