qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	"open list:Block layer core" <qemu-block@nongnu.org>,
	crosthwaite.peter@gmail.com, quintela@redhat.com,
	f4bug@amsat.org, dgilbert@redhat.com, kraxel@redhat.com,
	dirty.ice.hu@gmail.com, pbonzini@redhat.com,
	Max Reitz <mreitz@redhat.com>
Subject: Re: [PATCH v3] osdep: Make MIN/MAX evaluate arguments only once
Date: Wed, 3 Jun 2020 14:26:46 -0500	[thread overview]
Message-ID: <b4edd86c-a4cc-0b1d-ae28-009fe0a471e1@redhat.com> (raw)
In-Reply-To: <2e894b8d-a510-0689-83dc-f6c8da16410e@linaro.org>

On 6/3/20 11:32 AM, Richard Henderson wrote:

>>> I'd prefer we generate a compile-time error than a runtime trap (or nothing,
>>> depending on compiler flags controlling __builtin_unreachable).
>>
>> What we have DOES produce a compile-time error.  If either expression to
>> MIN_CONST() is not actually const, the fact that __builtin_unreachable()
>> returns void causes a compilation failure because a value is expected.
> 
> Ah!  Well, that's good and certainly sufficient for my needs.
> 
> I do now wonder if it wouldn't be clearer to use "(void)0"
> instead of __builtin_unreachable, and add a note to the comment just above.

Yes, I just tested; using "((void)0)" in place of 
"__builtin_unreachable()" has the same effect (no change to valid use, 
and still a compiler error on misuse). gcc:

/home/eblake/qemu/qemu-img.c: In function ‘is_allocated_sectors’:
/home/eblake/qemu/qemu-img.c:1225:15: error: void value not ignored as 
it ought to be
  1225 |             i = MIN_CONST(i, n);
       |               ^

clang:

/home/eblake/qemu/qemu-img.c:1225:15: error: assigning to 'int' from 
incompatible type 'void'
             i = MIN_CONST(i, n);
               ^ ~~~~~~~~~~~~~~~


Of course, a comment explaining the intent can't hurt either.  I'll wait 
to see if this gathers any other comments before spinning a v4 with that 
change.

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



  reply	other threads:[~2020-06-03 19:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03  1:36 [PATCH v3] osdep: Make MIN/MAX evaluate arguments only once Eric Blake
2020-06-03  2:07 ` Richard Henderson
2020-06-03  2:29   ` Eric Blake
2020-06-03 15:33     ` Eric Blake
2020-06-03 16:32     ` Richard Henderson
2020-06-03 19:26       ` Eric Blake [this message]
2020-06-04 18:39         ` Paolo Bonzini

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

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

  git send-email \
    --in-reply-to=b4edd86c-a4cc-0b1d-ae28-009fe0a471e1@redhat.com \
    --to=eblake@redhat.com \
    --cc=crosthwaite.peter@gmail.com \
    --cc=dgilbert@redhat.com \
    --cc=dirty.ice.hu@gmail.com \
    --cc=f4bug@amsat.org \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=richard.henderson@linaro.org \
    /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 NNTP newsgroup(s).