From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>, patches@linaro.org
Subject: Re: [Qemu-devel] [PATCH] hw/audio/fmopl.c: Avoid clang warning about shifting negative number
Date: Tue, 17 Nov 2015 10:45:38 +0100 [thread overview]
Message-ID: <564AF742.1070601@redhat.com> (raw)
In-Reply-To: <1447687010-4471-1-git-send-email-peter.maydell@linaro.org>
On 16/11/2015 16:16, Peter Maydell wrote:
> Newer versions of clang warn:
>
> hw/audio/fmopl.c:1085:39: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
> data = Limit( outd[0] , OPL_MAXOUT, OPL_MINOUT );
> ^~~~~~~~~~
> hw/audio/fmopl.c:75:28: note: expanded from macro 'OPL_MINOUT'
> #define OPL_MINOUT (-0x8000<<OPL_OUTSB)
> ~~~~~~~^
>
> Rephrase the definition of OPL_MINOUT to avoid the undefined behaviour.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> hw/audio/fmopl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
> index 81c0c1b..807b29c 100644
> --- a/hw/audio/fmopl.c
> +++ b/hw/audio/fmopl.c
> @@ -72,7 +72,7 @@ static int opl_dbg_maxchip,opl_dbg_chip;
> /* final output shift , limit minimum and maximum */
> #define OPL_OUTSB (TL_BITS+3-16) /* OPL output final shift 16bit */
> #define OPL_MAXOUT (0x7fff<<OPL_OUTSB)
> -#define OPL_MINOUT (-0x8000<<OPL_OUTSB)
> +#define OPL_MINOUT (-(0x8000<<OPL_OUTSB))
Again: let's stop this madness!!!!!!!!!!!!!!!!!!!!!!
(Yes, so many exclamation marks).
This is clearly computing -32768 * 2^N, not -(32768 * 2^N). The latter
is totally, utterly wrong, because 32768 is _not even expressible_ as a
16-bit fixed point value, which OPL_MINOUT/OPL_MAXOUT obviously are.
I'll shortly post a patch to disable this obnoxious warning.
Paolo
next prev parent reply other threads:[~2015-11-17 9:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-16 15:16 [Qemu-devel] [PATCH] hw/audio/fmopl.c: Avoid clang warning about shifting negative number Peter Maydell
2015-11-17 9:45 ` Paolo Bonzini [this message]
2015-11-17 10:17 ` Peter Maydell
2015-11-17 10:42 ` 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=564AF742.1070601@redhat.com \
--to=pbonzini@redhat.com \
--cc=kraxel@redhat.com \
--cc=patches@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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).