qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: qemu-devel@nongnu.org, stefanha@redhat.com,
	Juan Quintela <quintela@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 06/30] trace: Fix parameter types in migration
Date: Wed, 15 Mar 2017 14:55:16 -0500	[thread overview]
Message-ID: <9199bbb8-a6c5-be00-3bba-be128d68dd9f@redhat.com> (raw)
In-Reply-To: <8f837495-f773-9cad-004b-1f1f592c4244@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2928 bytes --]

On 03/14/2017 09:36 AM, Eric Blake wrote:

>>>> So why is a PRIx64 not the right way to print a __u64 ?
>>>
>>> Because __u64 is not the same type as uint64_t.  On 64-bit Linux, __u64
>>> is 'unsigned long long', while uint64_t is 'unsigned long'.
>>>
>>>> (I prefer %llx to the horrid PRIx64 syntax, but it still seems weird in this case)
>>>
>>> As it is, I'm not sure if __u64 is always 'unsigned long long' in ALL
>>> Linux clients; an even-more-conservative patch would be to switch all
>>> callers to use explicit casts to something (like uint64_t or unsigned
>>> long long) that we have full control over, rather than passing __u64
>>> where we have no control over what type it ultimately resolves to.
>>
>> That would be my preference - casting to (uint64_t) at the caller and
>> keep this as PRIx64.  We know it's a 64bit value so we should never
>> use unsigned long long anywhere for it.
> 
> Okay, my next version will insert an explicit cast in any caller that is
> otherwise passing a __u64 (since we can't guarantee what type __u64
> resolves to, and therefore what format string is appropriate for it).

Or maybe I will just omit those changes from my next version, in lieu of
a gcc bug report.  Here's my summary of an IRC conversation on the topic:

I just discovered that 32-bit mingw has a bug: it's <winsock.h> header
declared ntohl() as a function that returns 'u_long' ('unsigned long'),
but that POSIX requires ntohl() to return 'uin32_t' (which is 'unsigned
int' in that platform).  The only workaround to buggy system headers is
to insert casts at all call sites, or to quit using overly-picky
-Wformat warnings.

The gist of my gcc bug report will be that newer gcc recently introduced
a fine-tuning for -Wformat, namely -Wformat-signedness.  Some people
really do care about mismatches between "%d" and 'unsigned', or between
"%x" and 'int', but most of us don't.  When -Wformat was originally
invented, there was a lot of 32-bit code, and very little 64-bit code,
so it made TOTAL sense that you wanted to flag mismatches between "%d"
and 'long', or between "%ld" and 'int', as it was a porting aid to
64-bit platforms.  But these days, when we KNOW that a 32-bit platform
has 32-bit 'int' and 'long', and therefore that printf will behave
identically, it would be nice to squelch the warning, and instead only
issue it when there really is a mismatch (such as "%d" and 'long' on
64-bit).  If there were such a knob (call it -Wformat-rank), then in
qemu, we'd turn it off (-Wno-format-rank) so we can play fast and sloppy
with same-width but different-rank typedefs (such as the kernel's __u64
vs. uint64_t, or mingw's 'u_long' vs. 'uint32_t), but still get the full
benefit of real warnings when there is a 32-bit vs. 64-bit difference.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2017-03-15 19:55 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-13 19:55 [Qemu-devel] [PATCH for-2.9 v2 00/30] trace type mismatch cleanups Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 01/30] trace: Fix backwards mirror_yield parameters Eric Blake
2017-03-16  7:36   ` Stefan Hajnoczi
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 02/30] trace: Fix incorrect megasas trace parameters Eric Blake
2017-03-14  6:49   ` Hannes Reinecke
2017-03-16  7:36   ` Stefan Hajnoczi
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 03/30] trace: Avoid abuse of amdvi_mmio_read Eric Blake
2017-03-16  7:36   ` Stefan Hajnoczi
2017-03-23 15:23   ` Stefan Hajnoczi
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 04/30] trace: Fix parameter types in block Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 05/30] trace: Fix parameter types in io Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 06/30] trace: Fix parameter types in migration Eric Blake
2017-03-13 20:07   ` Dr. David Alan Gilbert
2017-03-13 20:18     ` Eric Blake
2017-03-14 11:32       ` Dr. David Alan Gilbert
2017-03-14 14:36         ` Eric Blake
2017-03-15 19:55           ` Eric Blake [this message]
2017-03-15 22:33             ` Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 07/30] trace: Fix parameter types in ui Eric Blake
2017-03-14  9:16   ` Gerd Hoffmann
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 08/30] trace: Fix parameter types in top level Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 09/30] trace: Fix parameter types in linux-user Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 10/30] trace: Fix parameter types in hw/acpi Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 11/30] trace: Fix parameter types in hw/audio Eric Blake
2017-03-14  9:16   ` Gerd Hoffmann
2017-03-22 15:10   ` Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 12/30] trace: Fix parameter types in hw/block Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 13/30] trace: Fix parameter types in hw/char Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 14/30] trace: Fix parameter types in hw/display Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 15/30] trace: Fix parameter types in hw/dma Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 16/30] trace: Fix parameter types in hw/i386 Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 17/30] trace: Fix parameter types in hw/input Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 18/30] trace: Fix parameter types in hw/intc Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 19/30] trace: Fix parameter types in hw/isa Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 20/30] trace: Fix parameter types in hw/misc Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 21/30] trace: Fix parameter types in hw/net Eric Blake
2017-03-14  7:21   ` Dmitry Fleytman
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 22/30] trace: Fix parameter types in hw/nvram Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 23/30] trace: Fix parameter types in hw/ppc Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 24/30] trace: Fix parameter types in hw/sd Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 25/30] trace: Fix parameter types in hw/scsi Eric Blake
2017-03-14  6:50   ` Hannes Reinecke
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 26/30] trace: Fix parameter types in hw/timer Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 27/30] trace: Fix parameter types in hw/usb Eric Blake
2017-03-14  9:16   ` Gerd Hoffmann
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 28/30] trace: Fix parameter types in hw/vfio Eric Blake
2017-03-13 19:55 ` [Qemu-devel] [PATCH v2 29/30] trace: Fix parameter types in hw/virtio Eric Blake
2017-03-16  7:45   ` Stefan Hajnoczi
2017-03-13 19:55 ` [Qemu-devel] [RFC PATCH v2 30/30] trace: Force compiler warnings on trace parameter type mismatches Eric Blake
2017-03-15 19:59   ` Eric Blake
2017-03-16  7:28     ` Stefan Hajnoczi
2017-03-13 20:27 ` [Qemu-devel] [PATCH for-2.9 v2 00/30] trace type mismatch cleanups no-reply

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=9199bbb8-a6c5-be00-3bba-be128d68dd9f@redhat.com \
    --to=eblake@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=stefanha@redhat.com \
    /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).