aboutsummaryrefslogtreecommitdiff
path: root/gcc/input.h
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2025-02-27 22:10:46 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2025-02-27 22:10:46 +0100
commit518def14ef1a8e6e307079f205ff98ad619ccd7b (patch)
tree6b51ba9eed12d21c1f669e6e2f4cc4ebee01c4f6 /gcc/input.h
parente333ad4ed82cdfb1b660e9666895641ef3ffaddb (diff)
downloadgcc-518def14ef1a8e6e307079f205ff98ad619ccd7b.zip
gcc-518def14ef1a8e6e307079f205ff98ad619ccd7b.tar.gz
gcc-518def14ef1a8e6e307079f205ff98ad619ccd7b.tar.bz2
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.
Diffstat (limited to 'gcc/input.h')
-rw-r--r--gcc/input.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/gcc/input.h b/gcc/input.h
index a60afe8..b0a1ca0 100644
--- a/gcc/input.h
+++ b/gcc/input.h
@@ -161,7 +161,7 @@ class file_cache
const char *buffer,
size_t sz);
- static void tune(size_t num_file_slots_, size_t lines);
+ void tune (size_t num_file_slots, size_t lines);
private:
file_cache_slot *evicted_cache_tab_entry (unsigned *highest_use_count);
@@ -169,7 +169,7 @@ class file_cache
file_cache_slot *lookup_file (const char *file_path);
private:
- static size_t num_file_slots;
+ size_t m_num_file_slots;
file_cache_slot *m_file_slots;
input_context m_input_context;
};