qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [Bug 1655708] [NEW] target/ppc/int_helper.c:2806: strange expression ?
@ 2017-01-11 16:41 dcb
  2017-01-11 17:12 ` Eric Blake
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: dcb @ 2017-01-11 16:41 UTC (permalink / raw)
  To: qemu-devel

Public bug reported:

target/ppc/int_helper.c:2806:25: warning: ‘*’ in boolean context,
suggest ‘&&’ instead [-Wint-in-bool-context]

Source code is

       zone_digit = (i * 2) ? b->u8[BCD_DIG_BYTE(i * 2)] >> 4 :
zone_lead;

Which I read as

       zone_digit = (i * 2) ? (b->u8[BCD_DIG_BYTE(i * 2)] >> 4) :
zone_lead;

so I think the compiler warning is for the i * 2 lhs of the ?.

I am not sure what to suggest as a bugfix.

** Affects: qemu
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1655708

Title:
  target/ppc/int_helper.c:2806: strange expression ?

Status in QEMU:
  New

Bug description:
  target/ppc/int_helper.c:2806:25: warning: ‘*’ in boolean context,
  suggest ‘&&’ instead [-Wint-in-bool-context]

  Source code is

         zone_digit = (i * 2) ? b->u8[BCD_DIG_BYTE(i * 2)] >> 4 :
  zone_lead;

  Which I read as

         zone_digit = (i * 2) ? (b->u8[BCD_DIG_BYTE(i * 2)] >> 4) :
  zone_lead;

  so I think the compiler warning is for the i * 2 lhs of the ?.

  I am not sure what to suggest as a bugfix.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1655708/+subscriptions

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [Bug 1655708] [NEW] target/ppc/int_helper.c:2806: strange expression ?
  2017-01-11 16:41 [Qemu-devel] [Bug 1655708] [NEW] target/ppc/int_helper.c:2806: strange expression ? dcb
@ 2017-01-11 17:12 ` Eric Blake
  2017-01-11 17:19   ` Thomas Huth
  2017-01-11 18:01   ` joserz
  2017-01-11 18:53 ` [Qemu-devel] [Bug 1655708] " Jose R. Ziviani
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 8+ messages in thread
From: Eric Blake @ 2017-01-11 17:12 UTC (permalink / raw)
  To: Bug 1655708, qemu-devel

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

On 01/11/2017 10:41 AM, dcb wrote:
> Public bug reported:
> 
> target/ppc/int_helper.c:2806:25: warning: ‘*’ in boolean context,
> suggest ‘&&’ instead [-Wint-in-bool-context]
> 
> Source code is
> 
>        zone_digit = (i * 2) ? b->u8[BCD_DIG_BYTE(i * 2)] >> 4 :
> zone_lead;

Also, looking at BCD_DIG_BYTE():

#if defined(HOST_WORDS_BIGENDIAN)
#define BCD_DIG_BYTE(n) (15 - (n/2))
#else
#define BCD_DIG_BYTE(n) (n/2)
#endif

Oops. n is under-parenthesized, and will cause invalid expansions for
some expressions.  Let's fix that as well.


> so I think the compiler warning is for the i * 2 lhs of the ?.

Yes - the compiler is complaining that 'i * 2' can only be non-zero if
'i' was non-zero (given that the code occurs in a loop for i between 0
and 16), so it is just as easy to write 'i ? ...' instead of the weirder
'(i * 2) ? ...'.

-- 
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 --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [Bug 1655708] [NEW] target/ppc/int_helper.c:2806: strange expression ?
  2017-01-11 17:12 ` Eric Blake
@ 2017-01-11 17:19   ` Thomas Huth
  2017-01-11 18:01   ` joserz
  1 sibling, 0 replies; 8+ messages in thread
From: Thomas Huth @ 2017-01-11 17:19 UTC (permalink / raw)
  To: Eric Blake, Bug 1655708, qemu-devel, Jose Ricardo Ziviani; +Cc: qemu-ppc

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

On 11.01.2017 18:12, Eric Blake wrote:
> On 01/11/2017 10:41 AM, dcb wrote:
>> so I think the compiler warning is for the i * 2 lhs of the ?.
> 
> Yes - the compiler is complaining that 'i * 2' can only be non-zero if
> 'i' was non-zero (given that the code occurs in a loop for i between 0
> and 16), so it is just as easy to write 'i ? ...' instead of the weirder
> '(i * 2) ? ...'.

... unless something like (i & 2) was meant instead?
Maybe Jose (who wrote that code) could comment on this?

 Thomas




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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [Bug 1655708] [NEW] target/ppc/int_helper.c:2806: strange expression ?
  2017-01-11 17:12 ` Eric Blake
  2017-01-11 17:19   ` Thomas Huth
@ 2017-01-11 18:01   ` joserz
  1 sibling, 0 replies; 8+ messages in thread
From: joserz @ 2017-01-11 18:01 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-devel

On Wed, Jan 11, 2017 at 05:12:38PM -0000, Eric Blake wrote:
> On 01/11/2017 10:41 AM, dcb wrote:
> > Public bug reported:
> > 
> > target/ppc/int_helper.c:2806:25: warning: ‘*’ in boolean context,
> > suggest ‘&&’ instead [-Wint-in-bool-context]
> > 
> > Source code is
> > 
> >        zone_digit = (i * 2) ? b->u8[BCD_DIG_BYTE(i * 2)] >> 4 :
> > zone_lead;
> 
> Also, looking at BCD_DIG_BYTE():
> 
> #if defined(HOST_WORDS_BIGENDIAN)
> #define BCD_DIG_BYTE(n) (15 - (n/2))
> #else
> #define BCD_DIG_BYTE(n) (n/2)
> #endif
> 
> Oops. n is under-parenthesized, and will cause invalid expansions for
> some expressions.  Let's fix that as well.
> 
Hello guys!!

Do you mean something like:

BCD_DIG_BYTE(n) (15 - ((n)/2)) and BCD_DIG_BYTE(n) ((n)/2) ?

to avoid issues like BCD_DIG_BYTE(i + 3) that will expand to (i + 3/2)
instead of ((i + 3)/2), right?

> 
> > so I think the compiler warning is for the i * 2 lhs of the ?.
> 
> Yes - the compiler is complaining that 'i * 2' can only be non-zero if
> 'i' was non-zero (given that the code occurs in a loop for i between 0
> and 16), so it is just as easy to write 'i ? ...' instead of the weirder
> '(i * 2) ? ...'.
> 

Yes, Eric is correct it's meant to be "(i) ? .. : .." because the sign
is located at position 0. I'm improving it. I'll send a patch for them
today.

Thanks!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [Bug 1655708] Re: target/ppc/int_helper.c:2806: strange expression ?
  2017-01-11 16:41 [Qemu-devel] [Bug 1655708] [NEW] target/ppc/int_helper.c:2806: strange expression ? dcb
  2017-01-11 17:12 ` Eric Blake
@ 2017-01-11 18:53 ` Jose R. Ziviani
  2017-01-11 20:09 ` dcb
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Jose R. Ziviani @ 2017-01-11 18:53 UTC (permalink / raw)
  To: qemu-devel

** Changed in: qemu
     Assignee: (unassigned) => Jose R. Ziviani (jrziviani)

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1655708

Title:
  target/ppc/int_helper.c:2806: strange expression ?

Status in QEMU:
  New

Bug description:
  target/ppc/int_helper.c:2806:25: warning: ‘*’ in boolean context,
  suggest ‘&&’ instead [-Wint-in-bool-context]

  Source code is

         zone_digit = (i * 2) ? b->u8[BCD_DIG_BYTE(i * 2)] >> 4 :
  zone_lead;

  Which I read as

         zone_digit = (i * 2) ? (b->u8[BCD_DIG_BYTE(i * 2)] >> 4) :
  zone_lead;

  so I think the compiler warning is for the i * 2 lhs of the ?.

  I am not sure what to suggest as a bugfix.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1655708/+subscriptions

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [Bug 1655708] Re: target/ppc/int_helper.c:2806: strange expression ?
  2017-01-11 16:41 [Qemu-devel] [Bug 1655708] [NEW] target/ppc/int_helper.c:2806: strange expression ? dcb
  2017-01-11 17:12 ` Eric Blake
  2017-01-11 18:53 ` [Qemu-devel] [Bug 1655708] " Jose R. Ziviani
@ 2017-01-11 20:09 ` dcb
  2017-01-18 15:44 ` Thomas Huth
  2017-07-20 12:44 ` Thomas Huth
  4 siblings, 0 replies; 8+ messages in thread
From: dcb @ 2017-01-11 20:09 UTC (permalink / raw)
  To: qemu-devel

> so it is just as easy to write 'i ? ...' instead of the weirder
> '(i * 2) ? ...'.

I suspect it is just possible that the i * 2 expression is a typo
for something else, perhaps i & 2 or i << 2 or i >> 2 or something else.

I don't know the code so I am unable to offer better guidance.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1655708

Title:
  target/ppc/int_helper.c:2806: strange expression ?

Status in QEMU:
  New

Bug description:
  target/ppc/int_helper.c:2806:25: warning: ‘*’ in boolean context,
  suggest ‘&&’ instead [-Wint-in-bool-context]

  Source code is

         zone_digit = (i * 2) ? b->u8[BCD_DIG_BYTE(i * 2)] >> 4 :
  zone_lead;

  Which I read as

         zone_digit = (i * 2) ? (b->u8[BCD_DIG_BYTE(i * 2)] >> 4) :
  zone_lead;

  so I think the compiler warning is for the i * 2 lhs of the ?.

  I am not sure what to suggest as a bugfix.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1655708/+subscriptions

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [Bug 1655708] Re: target/ppc/int_helper.c:2806: strange expression ?
  2017-01-11 16:41 [Qemu-devel] [Bug 1655708] [NEW] target/ppc/int_helper.c:2806: strange expression ? dcb
                   ` (2 preceding siblings ...)
  2017-01-11 20:09 ` dcb
@ 2017-01-18 15:44 ` Thomas Huth
  2017-07-20 12:44 ` Thomas Huth
  4 siblings, 0 replies; 8+ messages in thread
From: Thomas Huth @ 2017-01-18 15:44 UTC (permalink / raw)
  To: qemu-devel

Patch has been posted to the mailing list:
https://lists.gnu.org/archive/html/qemu-devel/2017-01/msg02008.html

** Changed in: qemu
       Status: New => In Progress

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1655708

Title:
  target/ppc/int_helper.c:2806: strange expression ?

Status in QEMU:
  In Progress

Bug description:
  target/ppc/int_helper.c:2806:25: warning: ‘*’ in boolean context,
  suggest ‘&&’ instead [-Wint-in-bool-context]

  Source code is

         zone_digit = (i * 2) ? b->u8[BCD_DIG_BYTE(i * 2)] >> 4 :
  zone_lead;

  Which I read as

         zone_digit = (i * 2) ? (b->u8[BCD_DIG_BYTE(i * 2)] >> 4) :
  zone_lead;

  so I think the compiler warning is for the i * 2 lhs of the ?.

  I am not sure what to suggest as a bugfix.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1655708/+subscriptions

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [Bug 1655708] Re: target/ppc/int_helper.c:2806: strange expression ?
  2017-01-11 16:41 [Qemu-devel] [Bug 1655708] [NEW] target/ppc/int_helper.c:2806: strange expression ? dcb
                   ` (3 preceding siblings ...)
  2017-01-18 15:44 ` Thomas Huth
@ 2017-07-20 12:44 ` Thomas Huth
  4 siblings, 0 replies; 8+ messages in thread
From: Thomas Huth @ 2017-07-20 12:44 UTC (permalink / raw)
  To: qemu-devel

Fix had been committed here:
http://git.qemu.org/?p=qemu.git;a=commitdiff;h=365206aeb3d0bb72043d

** Changed in: qemu
       Status: In Progress => Fix Released

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1655708

Title:
  target/ppc/int_helper.c:2806: strange expression ?

Status in QEMU:
  Fix Released

Bug description:
  target/ppc/int_helper.c:2806:25: warning: ‘*’ in boolean context,
  suggest ‘&&’ instead [-Wint-in-bool-context]

  Source code is

         zone_digit = (i * 2) ? b->u8[BCD_DIG_BYTE(i * 2)] >> 4 :
  zone_lead;

  Which I read as

         zone_digit = (i * 2) ? (b->u8[BCD_DIG_BYTE(i * 2)] >> 4) :
  zone_lead;

  so I think the compiler warning is for the i * 2 lhs of the ?.

  I am not sure what to suggest as a bugfix.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1655708/+subscriptions

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-07-20 12:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-11 16:41 [Qemu-devel] [Bug 1655708] [NEW] target/ppc/int_helper.c:2806: strange expression ? dcb
2017-01-11 17:12 ` Eric Blake
2017-01-11 17:19   ` Thomas Huth
2017-01-11 18:01   ` joserz
2017-01-11 18:53 ` [Qemu-devel] [Bug 1655708] " Jose R. Ziviani
2017-01-11 20:09 ` dcb
2017-01-18 15:44 ` Thomas Huth
2017-07-20 12:44 ` Thomas Huth

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).