bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Cc: "Tim Rühsen" <tim.ruehsen@gmx.de>
Subject: Re: clang-10 warning in hash.c
Date: Mon, 27 Jan 2020 14:09:50 +0100	[thread overview]
Message-ID: <3695940.OeVvW2AmiG@omega> (raw)
In-Reply-To: <ac0b82a1-816f-2fef-7009-2d4475531296@gmx.de>

Hi Tim,

> Not sure if the compiler is correct here, but maybe worth a look:
> 
> hash.c:549:11: error: implicit conversion from 'unsigned long' to
> 'float' changes value from 18446744073709551615 to 18446744073709551616
> [-Werror,-Wimplicit-int-float-conversion]
>       if (SIZE_MAX <= new_candidate)
>           ^~~~~~~~ ~~
> /usr/include/stdint.h:227:22: note: expanded from macro 'SIZE_MAX'
> #  define SIZE_MAX              (18446744073709551615UL)
>                                  ^~~~~~~~~~~~~~~~~~~~~~

This warning is pointless, because
  - Since the next float below 18446744073709551616 = 0x10000000000000000
    would be                   18446742974197923840 =  0xFFFFFF0000000000
    the comparison result is the same for the two values ...615 and ...616.
  - The compiler inserts the implicit conversion only because of the '<='
    operator.
IMO you should file a ticket with the clang people.

Inserting a cast to 'double'

  if ((double) SIZE_MAX <= (double) new_candidate)

would not help, because
the next double-float below 18446744073709551616 = 0x10000000000000000
would be                    18446744073709549568 =  0xFFFFFFFFFFFFF800

Bruno



  reply	other threads:[~2020-01-27 13:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-27 10:58 clang-10 warning in hash.c Tim Rühsen
2020-01-27 13:09 ` Bruno Haible [this message]
2020-01-27 20:16   ` Paul Eggert
2020-01-27 21:03     ` Bruno Haible
2020-01-28  2:08       ` Bruno Haible
2020-01-30 15:35   ` Tim Rühsen
2020-01-30 17:50     ` bugs.llvm.org Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3695940.OeVvW2AmiG@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=tim.ruehsen@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).