* [Qemu-devel] [PATCH] ide: fix enum comparison for gcc 4.7
@ 2017-09-20 19:41 John Snow
2017-09-20 19:48 ` Eric Blake
2017-09-20 21:28 ` Mark Cave-Ayland
0 siblings, 2 replies; 5+ messages in thread
From: John Snow @ 2017-09-20 19:41 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, mark.cave-ayland, John Snow
Apparently GCC gets bent over comparing enum values against zero.
Replace the conditional with something less readable.
Signed-off-by: John Snow <jsnow@redhat.com>
---
hw/ide/core.c | 2 +-
include/hw/ide/internal.h | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index a19bd90..d63eb4a 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -68,7 +68,7 @@ const char *IDE_DMA_CMD_lookup[IDE_DMA__COUNT] = {
static const char *IDE_DMA_CMD_str(enum ide_dma_cmd enval)
{
- if (enval >= IDE_DMA__BEGIN && enval < IDE_DMA__COUNT) {
+ if ((unsigned)enval < IDE_DMA__COUNT) {
return IDE_DMA_CMD_lookup[enval];
}
return "DMA UNKNOWN CMD";
diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h
index 180e00e..e641012 100644
--- a/include/hw/ide/internal.h
+++ b/include/hw/ide/internal.h
@@ -333,8 +333,7 @@ struct unreported_events {
};
enum ide_dma_cmd {
- IDE_DMA__BEGIN = 0,
- IDE_DMA_READ = IDE_DMA__BEGIN,
+ IDE_DMA_READ = 0,
IDE_DMA_WRITE,
IDE_DMA_TRIM,
IDE_DMA_ATAPI,
--
2.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] ide: fix enum comparison for gcc 4.7
2017-09-20 19:41 [Qemu-devel] [PATCH] ide: fix enum comparison for gcc 4.7 John Snow
@ 2017-09-20 19:48 ` Eric Blake
2017-09-20 21:28 ` Mark Cave-Ayland
1 sibling, 0 replies; 5+ messages in thread
From: Eric Blake @ 2017-09-20 19:48 UTC (permalink / raw)
To: John Snow, qemu-devel; +Cc: peter.maydell, mark.cave-ayland
[-- Attachment #1: Type: text/plain, Size: 615 bytes --]
On 09/20/2017 02:41 PM, John Snow wrote:
> Apparently GCC gets bent over comparing enum values against zero.
> Replace the conditional with something less readable.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> hw/ide/core.c | 2 +-
> include/hw/ide/internal.h | 3 +--
> 2 files changed, 2 insertions(+), 3 deletions(-)
Unfortunate that the compiler conspires against aesthetics, but such is
life.
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] ide: fix enum comparison for gcc 4.7
2017-09-20 19:41 [Qemu-devel] [PATCH] ide: fix enum comparison for gcc 4.7 John Snow
2017-09-20 19:48 ` Eric Blake
@ 2017-09-20 21:28 ` Mark Cave-Ayland
2017-09-20 21:33 ` John Snow
1 sibling, 1 reply; 5+ messages in thread
From: Mark Cave-Ayland @ 2017-09-20 21:28 UTC (permalink / raw)
To: John Snow, qemu-devel; +Cc: peter.maydell
On 20/09/17 20:41, John Snow wrote:
> Apparently GCC gets bent over comparing enum values against zero.
> Replace the conditional with something less readable.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> hw/ide/core.c | 2 +-
> include/hw/ide/internal.h | 3 +--
> 2 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/hw/ide/core.c b/hw/ide/core.c
> index a19bd90..d63eb4a 100644
> --- a/hw/ide/core.c
> +++ b/hw/ide/core.c
> @@ -68,7 +68,7 @@ const char *IDE_DMA_CMD_lookup[IDE_DMA__COUNT] = {
>
> static const char *IDE_DMA_CMD_str(enum ide_dma_cmd enval)
> {
> - if (enval >= IDE_DMA__BEGIN && enval < IDE_DMA__COUNT) {
> + if ((unsigned)enval < IDE_DMA__COUNT) {
> return IDE_DMA_CMD_lookup[enval];
> }
> return "DMA UNKNOWN CMD";
> diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h
> index 180e00e..e641012 100644
> --- a/include/hw/ide/internal.h
> +++ b/include/hw/ide/internal.h
> @@ -333,8 +333,7 @@ struct unreported_events {
> };
>
> enum ide_dma_cmd {
> - IDE_DMA__BEGIN = 0,
> - IDE_DMA_READ = IDE_DMA__BEGIN,
> + IDE_DMA_READ = 0,
> IDE_DMA_WRITE,
> IDE_DMA_TRIM,
> IDE_DMA_ATAPI,
>
Really close - it fixes the error in hw/ide/core.c but then I see a
similar error a bit later in hw/ide/ahci.c:
cc -I/home/build/src/qemu/git/qemu/hw/ide -Ihw/ide
-I/home/build/src/qemu/git/qemu/tcg
-I/home/build/src/qemu/git/qemu/tcg/i386
-I/home/build/src/qemu/git/qemu/linux-headers
-I/home/build/src/qemu/git/qemu/linux-headers -I.
-I/home/build/src/qemu/git/qemu
-I/home/build/src/qemu/git/qemu/accel/tcg
-I/home/build/src/qemu/git/qemu/include -I/usr/include/pixman-1
-I/home/build/src/qemu/git/qemu/dtc/libfdt -Werror -pthread
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
-m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings
-Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv
-Wendif-labels -Wno-missing-include-dirs -Wempty-body -Wnested-externs
-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers
-Wold-style-declaration -Wold-style-definition -Wtype-limits
-fstack-protector-all -I/usr/include/p11-kit-1
-I/usr/include/libpng12 -I/home/build/src/qemu/git/qemu/tests -MMD -MP
-MT hw/ide/ahci.o -MF hw/ide/ahci.d -O2 -U_FORTIFY_SOURCE
-D_FORTIFY_SOURCE=2 -g -c -o hw/ide/ahci.o hw/ide/ahci.c
hw/ide/ahci.c: In function ‘ahci_trigger_irq’:
hw/ide/ahci.c:187:5: error: comparison of unsigned expression >= 0 is
always true [-Werror=type-limits]
cc1: all warnings being treated as errors
make: *** [hw/ide/ahci.o] Error 1
ATB,
Mark.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] ide: fix enum comparison for gcc 4.7
2017-09-20 21:28 ` Mark Cave-Ayland
@ 2017-09-20 21:33 ` John Snow
2017-09-20 21:41 ` Mark Cave-Ayland
0 siblings, 1 reply; 5+ messages in thread
From: John Snow @ 2017-09-20 21:33 UTC (permalink / raw)
To: Mark Cave-Ayland, qemu-devel; +Cc: peter.maydell
On 09/20/2017 05:28 PM, Mark Cave-Ayland wrote:
> On 20/09/17 20:41, John Snow wrote:
>
>> Apparently GCC gets bent over comparing enum values against zero.
>> Replace the conditional with something less readable.
>>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>> ---
>> hw/ide/core.c | 2 +-
>> include/hw/ide/internal.h | 3 +--
>> 2 files changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/hw/ide/core.c b/hw/ide/core.c
>> index a19bd90..d63eb4a 100644
>> --- a/hw/ide/core.c
>> +++ b/hw/ide/core.c
>> @@ -68,7 +68,7 @@ const char *IDE_DMA_CMD_lookup[IDE_DMA__COUNT] = {
>>
>> static const char *IDE_DMA_CMD_str(enum ide_dma_cmd enval)
>> {
>> - if (enval >= IDE_DMA__BEGIN && enval < IDE_DMA__COUNT) {
>> + if ((unsigned)enval < IDE_DMA__COUNT) {
>> return IDE_DMA_CMD_lookup[enval];
>> }
>> return "DMA UNKNOWN CMD";
>> diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h
>> index 180e00e..e641012 100644
>> --- a/include/hw/ide/internal.h
>> +++ b/include/hw/ide/internal.h
>> @@ -333,8 +333,7 @@ struct unreported_events {
>> };
>>
>> enum ide_dma_cmd {
>> - IDE_DMA__BEGIN = 0,
>> - IDE_DMA_READ = IDE_DMA__BEGIN,
>> + IDE_DMA_READ = 0,
>> IDE_DMA_WRITE,
>> IDE_DMA_TRIM,
>> IDE_DMA_ATAPI,
>>
>
> Really close - it fixes the error in hw/ide/core.c but then I see a
> similar error a bit later in hw/ide/ahci.c:
>
> cc -I/home/build/src/qemu/git/qemu/hw/ide -Ihw/ide
> -I/home/build/src/qemu/git/qemu/tcg
> -I/home/build/src/qemu/git/qemu/tcg/i386
> -I/home/build/src/qemu/git/qemu/linux-headers
> -I/home/build/src/qemu/git/qemu/linux-headers -I.
> -I/home/build/src/qemu/git/qemu
> -I/home/build/src/qemu/git/qemu/accel/tcg
> -I/home/build/src/qemu/git/qemu/include -I/usr/include/pixman-1
> -I/home/build/src/qemu/git/qemu/dtc/libfdt -Werror -pthread
> -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
> -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
> -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings
> -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv
> -Wendif-labels -Wno-missing-include-dirs -Wempty-body -Wnested-externs
> -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers
> -Wold-style-declaration -Wold-style-definition -Wtype-limits
> -fstack-protector-all -I/usr/include/p11-kit-1
> -I/usr/include/libpng12 -I/home/build/src/qemu/git/qemu/tests -MMD -MP
> -MT hw/ide/ahci.o -MF hw/ide/ahci.d -O2 -U_FORTIFY_SOURCE
> -D_FORTIFY_SOURCE=2 -g -c -o hw/ide/ahci.o hw/ide/ahci.c
> hw/ide/ahci.c: In function ‘ahci_trigger_irq’:
> hw/ide/ahci.c:187:5: error: comparison of unsigned expression >= 0 is
> always true [-Werror=type-limits]
> cc1: all warnings being treated as errors
> make: *** [hw/ide/ahci.o] Error 1
>
>
> ATB,
>
> Mark.
>
Man, what's with your compiler? ...
OK, let's try:
diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 24c65df..32d1296 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -184,7 +184,7 @@ static void ahci_check_irq(AHCIState *s)
static void ahci_trigger_irq(AHCIState *s, AHCIDevice *d,
enum AHCIPortIRQ irqbit)
{
- g_assert(irqbit >= 0 && irqbit < 32);
+ g_assert((unsigned)irqbit < 32);
uint32_t irq = 1U << irqbit;
uint32_t irqstat = d->port_regs.irq_stat | irq;
I can't remember immediately if I have more spots that might cause a
ruckus for you.
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] ide: fix enum comparison for gcc 4.7
2017-09-20 21:33 ` John Snow
@ 2017-09-20 21:41 ` Mark Cave-Ayland
0 siblings, 0 replies; 5+ messages in thread
From: Mark Cave-Ayland @ 2017-09-20 21:41 UTC (permalink / raw)
To: John Snow, qemu-devel; +Cc: peter.maydell
On 20/09/17 22:33, John Snow wrote:
> On 09/20/2017 05:28 PM, Mark Cave-Ayland wrote:
>> On 20/09/17 20:41, John Snow wrote:
>>
>>> Apparently GCC gets bent over comparing enum values against zero.
>>> Replace the conditional with something less readable.
>>>
>>> Signed-off-by: John Snow <jsnow@redhat.com>
>>> ---
>>> hw/ide/core.c | 2 +-
>>> include/hw/ide/internal.h | 3 +--
>>> 2 files changed, 2 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/hw/ide/core.c b/hw/ide/core.c
>>> index a19bd90..d63eb4a 100644
>>> --- a/hw/ide/core.c
>>> +++ b/hw/ide/core.c
>>> @@ -68,7 +68,7 @@ const char *IDE_DMA_CMD_lookup[IDE_DMA__COUNT] = {
>>>
>>> static const char *IDE_DMA_CMD_str(enum ide_dma_cmd enval)
>>> {
>>> - if (enval >= IDE_DMA__BEGIN && enval < IDE_DMA__COUNT) {
>>> + if ((unsigned)enval < IDE_DMA__COUNT) {
>>> return IDE_DMA_CMD_lookup[enval];
>>> }
>>> return "DMA UNKNOWN CMD";
>>> diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h
>>> index 180e00e..e641012 100644
>>> --- a/include/hw/ide/internal.h
>>> +++ b/include/hw/ide/internal.h
>>> @@ -333,8 +333,7 @@ struct unreported_events {
>>> };
>>>
>>> enum ide_dma_cmd {
>>> - IDE_DMA__BEGIN = 0,
>>> - IDE_DMA_READ = IDE_DMA__BEGIN,
>>> + IDE_DMA_READ = 0,
>>> IDE_DMA_WRITE,
>>> IDE_DMA_TRIM,
>>> IDE_DMA_ATAPI,
>>>
>>
>> Really close - it fixes the error in hw/ide/core.c but then I see a
>> similar error a bit later in hw/ide/ahci.c:
>>
>> cc -I/home/build/src/qemu/git/qemu/hw/ide -Ihw/ide
>> -I/home/build/src/qemu/git/qemu/tcg
>> -I/home/build/src/qemu/git/qemu/tcg/i386
>> -I/home/build/src/qemu/git/qemu/linux-headers
>> -I/home/build/src/qemu/git/qemu/linux-headers -I.
>> -I/home/build/src/qemu/git/qemu
>> -I/home/build/src/qemu/git/qemu/accel/tcg
>> -I/home/build/src/qemu/git/qemu/include -I/usr/include/pixman-1
>> -I/home/build/src/qemu/git/qemu/dtc/libfdt -Werror -pthread
>> -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
>> -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
>> -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings
>> -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv
>> -Wendif-labels -Wno-missing-include-dirs -Wempty-body -Wnested-externs
>> -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers
>> -Wold-style-declaration -Wold-style-definition -Wtype-limits
>> -fstack-protector-all -I/usr/include/p11-kit-1
>> -I/usr/include/libpng12 -I/home/build/src/qemu/git/qemu/tests -MMD -MP
>> -MT hw/ide/ahci.o -MF hw/ide/ahci.d -O2 -U_FORTIFY_SOURCE
>> -D_FORTIFY_SOURCE=2 -g -c -o hw/ide/ahci.o hw/ide/ahci.c
>> hw/ide/ahci.c: In function ‘ahci_trigger_irq’:
>> hw/ide/ahci.c:187:5: error: comparison of unsigned expression >= 0 is
>> always true [-Werror=type-limits]
>> cc1: all warnings being treated as errors
>> make: *** [hw/ide/ahci.o] Error 1
>>
>>
>> ATB,
>>
>> Mark.
>>
>
> Man, what's with your compiler? ...
>
> OK, let's try:
>
> diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
> index 24c65df..32d1296 100644
> --- a/hw/ide/ahci.c
> +++ b/hw/ide/ahci.c
> @@ -184,7 +184,7 @@ static void ahci_check_irq(AHCIState *s)
> static void ahci_trigger_irq(AHCIState *s, AHCIDevice *d,
> enum AHCIPortIRQ irqbit)
> {
> - g_assert(irqbit >= 0 && irqbit < 32);
> + g_assert((unsigned)irqbit < 32);
> uint32_t irq = 1U << irqbit;
> uint32_t irqstat = d->port_regs.irq_stat | irq;
>
>
> I can't remember immediately if I have more spots that might cause a
> ruckus for you.
Nope, that's all folks! Combining these two together fixes the build for
me again:
Tested-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
ATB,
Mark.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-09-20 21:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-20 19:41 [Qemu-devel] [PATCH] ide: fix enum comparison for gcc 4.7 John Snow
2017-09-20 19:48 ` Eric Blake
2017-09-20 21:28 ` Mark Cave-Ayland
2017-09-20 21:33 ` John Snow
2017-09-20 21:41 ` Mark Cave-Ayland
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).