On Mon, 2025-01-27 at 11:25 -0500, David Malcolm wrote: > On Sat, 2025-01-25 at 23:31 -0800, Andi Kleen wrote: > > From: Andi Kleen <a...@gcc.gnu.org> > > Thanks for writing the test case! > > Some nitpicks... > > > > > > gcc/ChangeLog: > > > > * input.cc (check_line): New. > > (test_replacement): New function to test line caching. > > (input_cc_tests): Call test_replacement > > --- > > gcc/input.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 46 insertions(+) > > > > diff --git a/gcc/input.cc b/gcc/input.cc > > index f1a15de66f1..524d5d2b6d1 100644 > > --- a/gcc/input.cc > > +++ b/gcc/input.cc > > @@ -2346,6 +2346,51 @@ test_make_location_nonpure_range_endpoints > > (const line_table_case &case_) > > ASSERT_FALSE (IS_ADHOC_LOC (get_finish (not_aaa_eq_bbb))); > > } > > > > +/* Verify reading of a specific line LINENUM in TMP, FC. */ > > + > > +static void check_line (temp_source_file &tmp, file_cache &fc, int > > linenum) > > +{ > > + char_span line = fc.get_source_line (tmp.get_filename (), > > linenum); > > + int n; > > + ASSERT_TRUE (sscanf (line.get_buffer (), "%d", &n) == 1); > > Please add a comment around here something like: > > /* Although get_buffer's result isn't guaranteed to be > null-terminated, it will be for every line in test_replacement. > */ > > or somesuch.
...or rather, sscanf will always hit a "\n" character before running off the end of the buffer for the uses within test_replacement. Dave