[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedo
From: |
Greg Kurz |
Subject: |
Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26 |
Date: |
Thu, 3 Aug 2017 20:38:05 +0200 |
On Thu, 3 Aug 2017 11:07:13 -0300
Philippe Mathieu-Daudé <address@hidden> wrote:
> On 08/03/2017 10:55 AM, Eric Blake wrote:
> > On 08/03/2017 08:34 AM, Philippe Mathieu-Daudé wrote:
> >> Hi Greg,
> >>
> >> On 08/02/2017 11:47 AM, Greg Kurz wrote:
> >>> Building QEMU on fedora26 with the latest gcc package fails:
> >>>
> >>> CC ppc64-softmmu/target/ppc/kvm.o
> >>> In file included from include/sysemu/hw_accel.h:16:0,
> >>> from target/ppc/kvm.c:31:
> >>> target/ppc/kvm.c: In function ‘kvmppc_booke_watchdog_enable’:
> >>> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used
> >>> uninitialized
> >
> >>
> >> This sizeof() use looks unnatural to me. I wonder why not use size_t,
> >> since this is about sizeof()/ARRAY_SIZE(). The problem seems to come
> >> from the commit this cast was introduced (61c7bbd236):
> >>
> >> target-ppc/kvm.c:1302:21: error: comparison of unsigned expression < 0
> >> is always false [-Werror=type-limits]
> >>
> >> So I'd rather suggest this code, which looks more natural to read to me:
> >>
> >> if (ARRAY_SIZE(args_tmp)) {
> >> for (i = 0; i < ARRAY_SIZE(args_tmp) && ...
>
> Oops I forgot to suggest size_t i.
>
> >
> > For that matter, the existing code is doing:
> >
> > int i;
> > i < (int)ARRAY_SIZE(args_tmp)
> >
> > but wouldn't that be better as:
> >
> > size_t i;
> > i < ARRAY_SIZE(args_temp)
> >
> > I guess we have both the old compilers (per commit 61c7bbd2) and the new
> > to worry about; although I was unable to reproduce it on Fedora 26 on
> > x86_64 (is this an architecture-dependent compiler bug?)
> >
>
The following code snippet spits a warning with gcc-7.1.1-3.fc26 and -Wall on
ppc64le AND x86_64:
int foo(void)
{
char empty_array[] = { };
int i, ret = 0;
for (i = 0; i < (int) (sizeof(empty_array) / sizeof(empty_array[0])); i++) {
ret = empty_array[i];
}
return ret;
}
If I drop the (int), the warning goes away... and so does the build break
of qemu-system-ppc64 on my ppc64le host.
I don't have 4.7.1 or 4.6 compilers around but I could check 4.8.5
is okay with that change FWIW.
> Ok so let's stop losing time about compiler incoherent warnings, using
> -Wno-type-limits for GCC < 5...
> So we can keep a sane/understandable codebase, using size_t and no (int)
> cast.
>
If I also convert 'int i' to 'size_t i' then I get the same error as
in commit 61c7bbd2:
error: comparison of unsigned expression < 0 is always
false [-Werror=type-limits]
> Phil.
pgpbLE5zmZjpm.pgp
Description: OpenPGP digital signature
Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26, Greg Kurz, 2017/08/03
Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26, Philippe Mathieu-Daudé, 2017/08/03
Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26, Greg Kurz, 2017/08/03