qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH for 2.5] QEMU does not care about left shifts of signed negative values
Date: Tue, 17 Nov 2015 10:59:41 +0100	[thread overview]
Message-ID: <1447754381-29882-1-git-send-email-pbonzini@redhat.com> (raw)

There's no reason for the compiler to exploit the undefinedness of left
shifts, In fact GCC explicitly documents that they do not use at all
all this possibility.  They also say this is subject to change, but
they have been saying this for 10 years (since the wording appeared in
the GCC 4.0 manual).

Any workaround for this particular case of undefined behavior uglifies
the code: using unsigned is unsafe because the value becomes positive
when extended; using -(a << b) does not express as well that the
intention is to compute -a * 2^N.

Clang has just added an obnoxious, pointless, *totally useless*, unsafe
warning about this.  It's obnoxious and pointless because the compiler
is not using the latitude that the standard gives it, so it just adds
noise.  It is useless and unsafe because it does not catch the widely
more common case where the LHS is a variable, and thus gives a false
sense of security.

The noisy nature of the warning means that it should have never been
added to -Wall.  The uselessness means that it probably should not
have even been added to -Wextra.

Document this explicitly, and shut up the stupid warning.
</rant>

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 HACKING   | 4 ++++
 configure | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/HACKING b/HACKING
index 12fbc8a..ece6d5b 100644
--- a/HACKING
+++ b/HACKING
@@ -157,3 +157,7 @@ painful. These are:
  * you may assume that integers are 2s complement representation
  * you may assume that right shift of a signed integer duplicates
    the sign bit (ie it is an arithmetic shift, not a logical shift)
+
+In addition, QEMU assumes that the compiler does not use the latitude
+given in C99 and C11 to treat aspects of signed '<<' as undefined, as
+documented in the GNU Compiler Collection manual starting at version 4.0.
diff --git a/configure b/configure
index 6bfa6f5..e54c2ed 100755
--- a/configure
+++ b/configure
@@ -1428,7 +1428,7 @@ fi
 gcc_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits"
 gcc_flags="-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers $gcc_flags"
 gcc_flags="-Wmissing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
-gcc_flags="-Wendif-labels $gcc_flags"
+gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
 gcc_flags="-Wno-initializer-overrides $gcc_flags"
 gcc_flags="-Wno-string-plus-int $gcc_flags"
 # Note that we do not add -Werror to gcc_flags here, because that would
-- 
2.5.0

             reply	other threads:[~2015-11-17  9:59 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-17  9:59 Paolo Bonzini [this message]
2015-11-17 10:19 ` [Qemu-devel] [PATCH for 2.5] QEMU does not care about left shifts of signed negative values Peter Maydell
2015-11-17 10:28   ` Paolo Bonzini
2015-11-17 10:36     ` Peter Maydell
2015-11-17 10:37       ` Paolo Bonzini
2015-11-17 10:42         ` Peter Maydell
2015-11-17 10:55         ` Peter Maydell
2015-11-17 10:57           ` Paolo Bonzini
2015-11-17 11:22             ` Peter Maydell
2015-11-17 12:10               ` Paolo Bonzini
2015-11-17 12:22                 ` Peter Maydell
2015-11-17 10:41     ` Laszlo Ersek
2015-11-17 10:43       ` Paolo Bonzini
2015-11-17 10:52         ` Laszlo Ersek
2015-11-17 11:59       ` Markus Armbruster
2015-11-17 12:04         ` Peter Maydell
2015-11-17 12:17           ` Laszlo Ersek
2015-11-17 13:48           ` Paolo Bonzini
2015-11-17 12:18         ` Laszlo Ersek
2015-11-17 10:26 ` Markus Armbruster
2015-11-17 10:36   ` Laszlo Ersek

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=1447754381-29882-1-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --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).