This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PR24392, Clang warning Wtautological-constant-out-of-range-compare
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Date: Thu, 28 Mar 2019 17:33:10 +1030
- Subject: PR24392, Clang warning Wtautological-constant-out-of-range-compare
PR 24392
* configure.ac: Invoke AC_CHECK_SIZEOF(int).
* configure: Regenerate.
* coffgen.c (coff_get_reloc_upper_bound): Replace gcc diagnostic
workaround with SIZEOF_LONG vs. SIZEOF_INT check.
* elf.c (_bfd_elf_get_reloc_upper_bound): Likewise.
* elf64-sparc.c (elf64_sparc_get_reloc_upper_bound): Likewise.
* mach-o.c (bfd_mach_o_get_reloc_upper_bound): Likewise.
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index ccf4b4302c..139ff9749a 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -2007,10 +2007,6 @@ coff_get_normalized_symtab (bfd *abfd)
return internal;
}
-#if GCC_VERSION >= 4003
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wtype-limits"
-#endif
long
coff_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
{
@@ -2019,16 +2015,15 @@ coff_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
bfd_set_error (bfd_error_invalid_operation);
return -1;
}
+#if SIZEOF_LONG == SIZEOF_INT
if (asect->reloc_count >= LONG_MAX / sizeof (arelent *))
{
bfd_set_error (bfd_error_file_too_big);
return -1;
}
+#endif
return (asect->reloc_count + 1) * sizeof (arelent *);
}
-#if GCC_VERSION >= 4003
-# pragma GCC diagnostic pop
-#endif
asymbol *
coff_make_empty_symbol (bfd *abfd)
diff --git a/bfd/configure.ac b/bfd/configure.ac
index 5f02c41520..4cd946db00 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -189,6 +189,7 @@ AC_TYPE_LONG_DOUBLE
AC_CHECK_TYPES([long long], [AC_CHECK_SIZEOF(long long)])
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(long)
+AC_CHECK_SIZEOF(int)
if test "x${ac_cv_sizeof_void_p}" = "x8"; then
host64=true
diff --git a/bfd/elf.c b/bfd/elf.c
index 73fb86971f..13f96e8840 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -8268,25 +8268,19 @@ _bfd_elf_get_dynamic_symtab_upper_bound (bfd *abfd)
return symtab_size;
}
-#if GCC_VERSION >= 4003
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wtype-limits"
-#endif
long
_bfd_elf_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
sec_ptr asect)
{
-
+#if SIZEOF_LONG == SIZEOF_INT
if (asect->reloc_count >= LONG_MAX / sizeof (arelent *))
{
bfd_set_error (bfd_error_file_too_big);
return -1;
}
+#endif
return (asect->reloc_count + 1) * sizeof (arelent *);
}
-#if GCC_VERSION >= 4003
-# pragma GCC diagnostic pop
-#endif
/* Canonicalize the relocs. */
diff --git a/bfd/elf64-sparc.c b/bfd/elf64-sparc.c
index f523ce7f84..55a1db911e 100644
--- a/bfd/elf64-sparc.c
+++ b/bfd/elf64-sparc.c
@@ -34,23 +34,18 @@
section can represent up to two relocs, we must tell the user to allocate
more space. */
-#if GCC_VERSION >= 4003
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wtype-limits"
-#endif
static long
elf64_sparc_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
{
+#if SIZEOF_LONG == SIZEOF_INT
if (sec->reloc_count >= LONG_MAX / 2 / sizeof (arelent *))
{
bfd_set_error (bfd_error_file_too_big);
return -1;
}
+#endif
return (sec->reloc_count * 2 + 1) * sizeof (arelent *);
}
-#if GCC_VERSION >= 4003
-# pragma GCC diagnostic pop
-#endif
static long
elf64_sparc_get_dynamic_reloc_upper_bound (bfd *abfd)
diff --git a/bfd/mach-o.c b/bfd/mach-o.c
index a9ca313501..122a0c26cc 100644
--- a/bfd/mach-o.c
+++ b/bfd/mach-o.c
@@ -1417,24 +1417,19 @@ bfd_mach_o_write_dyld_info (bfd *abfd, bfd_mach_o_load_command *command)
return TRUE;
}
-#if GCC_VERSION >= 4003
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wtype-limits"
-#endif
long
bfd_mach_o_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
asection *asect)
{
+#if SIZEOF_LONG == SIZEOF_INT
if (asect->reloc_count >= LONG_MAX / sizeof (arelent *))
{
bfd_set_error (bfd_error_file_too_big);
return -1;
}
+#endif
return (asect->reloc_count + 1) * sizeof (arelent *);
}
-#if GCC_VERSION >= 4003
-# pragma GCC diagnostic pop
-#endif
/* In addition to the need to byte-swap the symbol number, the bit positions
of the fields in the relocation information vary per target endian-ness. */
--
Alan Modra
Australia Development Lab, IBM