On Thu, Jul 25, 2024 at 07:48:38PM -0400, Siddhesh Poyarekar wrote: > The code to scale ranges for wide chars in format_string incorrectly > checks range.likely to scale range.unlikely, which is a copy-paste typo > from the immediate previous condition. > > gcc/ChangeLog: > > gimple-ssa-sprintf.cc (format_string): Fix type in range check > for UNLIKELY for wide chars. > > Signed-off-by: Siddhesh Poyarekar <siddh...@gotplt.org>
LGTM. What exactly the code really wants to do is unclear to me, what does the INT_MAX on the target have to do with the minimum/maximum/expected sizes of %S or %ls printed strings is unclear, target PTRDIFF_MAX maybe. And why it uses this if (slen.range.something < target_int_max ()) slen.range.something *= something_else; rather than say slen.range.something = MIN (slang.range.something * something_else, target_int_max ()); perhaps with some overflow checking is also something that is hard to guess. In any case, I think your patch is a step in the right direction. > --- a/gcc/gimple-ssa-sprintf.cc > +++ b/gcc/gimple-ssa-sprintf.cc > @@ -2623,7 +2623,7 @@ format_string (const directive &dir, tree arg, > pointer_query &ptr_qry) > if (slen.range.likely < target_int_max ()) > slen.range.likely *= 2; > > - if (slen.range.likely < target_int_max ()) > + if (slen.range.unlikely < target_int_max ()) > slen.range.unlikely *= target_mb_len_max (); > > /* A non-empty wide character conversion may fail. */ > -- > 2.45.1 Jakub