qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC PATCH 2/2] linux-user/mmap: Fix Clang 'type-limit-compare' warn


From: Eric Blake
Subject: Re: [RFC PATCH 2/2] linux-user/mmap: Fix Clang 'type-limit-compare' warning
Date: Wed, 3 Jun 2020 11:06:50 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0

On 5/3/20 6:32 AM, Philippe Mathieu-Daudé wrote:
When building with Clang 10 on Fedora 32, we get:

     CC      linux-user/mmap.o
   linux-user/mmap.c:720:49: error: result of comparison 'unsigned long' > 
18446744073709551615 is always false [-Werror,-Wtautological-type-limit-compare]
           if ((unsigned long)host_addr + new_size > (abi_ulong)-1) {
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~

Fix by restricting the check for when target sizeof(abi_ulong) is
smaller than target sizeof(unsigned long).

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
  linux-user/mmap.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index e378033797..b14652d894 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -714,6 +714,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong 
old_size,
              errno = ENOMEM;
              host_addr = MAP_FAILED;
          }
+#if TARGET_ABI_BITS < TARGET_LONG_BITS
          /* Check if address fits target address space */
          if ((unsigned long)host_addr + new_size > (abi_ulong)-1) {

Instead of using #if, the following suffices to shut up clang:

diff --git c/linux-user/mmap.c w/linux-user/mmap.c
index e37803379747..8d9ba201625d 100644
--- c/linux-user/mmap.c
+++ w/linux-user/mmap.c
@@ -715,7 +715,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
             host_addr = MAP_FAILED;
         }
         /* Check if address fits target address space */
-        if ((unsigned long)host_addr + new_size > (abi_ulong)-1) {
+        if ((unsigned long)host_addr > (abi_ulong)-1 - new_size) {
             /* Revert mremap() changes */
             host_addr = mremap(g2h(old_addr), new_size, old_size, flags);
             errno = ENOMEM;


That is, it is no longer a tautological type compare if you commute the operations so that neither side is a compile-time constant.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]