On Wed, 17 Jul 2024, Jakub Jelinek wrote: > Hi! > > Apparently there is a -Wsign-compare warning if ptrdiff_t has precision of > int, then (t - s + 1 + 2) / 3 * 4 has int type while cnt unsigned int. > This doesn't warn if ptrdiff_t has larger precision, say on x86_64 > it is 64-bit and so (t - s + 1 + 2) / 3 * 4 has long type and cnt unsigned > int. And it doesn't warn when using older binutils (in my tests I've > used new binutils on x86_64 and old binutils on i686). > Anyway, earlier condition guarantees that t - s is at most 256-ish and > t >= s by construction, so we can just cast it to (unsigned) to avoid > the warning. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK. > 2024-07-17 Jakub Jelinek <ja...@redhat.com> > > PR other/115958 > * varasm.cc (default_elf_asm_output_ascii): Cast t - s to unsigned > to avoid -Wsign-compare warnings. > > --- gcc/varasm.cc.jj 2024-07-16 19:33:53.553501415 +0200 > +++ gcc/varasm.cc 2024-07-16 22:35:05.132495049 +0200 > @@ -8558,7 +8558,7 @@ default_elf_asm_output_ascii (FILE *f, c > { > if (t == p && t != s) > { > - if (cnt <= (t - s + 1 + 2) / 3 * 4 > + if (cnt <= ((unsigned) (t - s) + 1 + 2) / 3 * 4 > && (!prev_base64 || (t - s) >= 16) > && ((t - s) > 1 || cnt <= 2)) > { > @@ -8584,7 +8584,7 @@ default_elf_asm_output_ascii (FILE *f, c > break; > } > } > - if (cnt > (t - s + 2) / 3 * 4 && (t - s) >= 3) > + if (cnt > ((unsigned) (t - s) + 2) / 3 * 4 && (t - s) >= 3) > { > if (bytes_in_chunk > 0) > { > > Jakub > > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)