]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
varasm: Fix bootstrap after the .base64 changes [PR115958]
authorJakub Jelinek <jakub@redhat.com>
Wed, 17 Jul 2024 09:40:03 +0000 (11:40 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 17 Jul 2024 09:40:03 +0000 (11:40 +0200)
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.

2024-07-17  Jakub Jelinek  <jakub@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

index fe0a6b873ef4da833952cfdf1e16bdc79756f79c..ecd91a68323734793549f74cf426cdbed89c1140 100644 (file)
@@ -8543,7 +8543,7 @@ default_elf_asm_output_ascii (FILE *f, const char *s, unsigned int len)
            {
              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))
                    {
@@ -8569,7 +8569,7 @@ default_elf_asm_output_ascii (FILE *f, const char *s, unsigned int len)
                  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)
                {