qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Michael Walle <michael@walle.cc>,
	Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PATCH 2/2] milkymist-pfpu: fix GCC 5.0.0 aggressive-loop-optimizations warning
Date: Fri, 20 Feb 2015 17:06:16 +0100	[thread overview]
Message-ID: <1424448376-15599-3-git-send-email-rkrcmar@redhat.com> (raw)
In-Reply-To: <1424448376-15599-1-git-send-email-rkrcmar@redhat.com>

man gcc:
  Warn if in a loop with constant number of iterations the compiler
  detects undefined behavior in some statement during one or more of
  the iterations.

Milkymist pfpu has no jump instructions, so checking for MICROCODE_WORDS
instructions should have kept us in bounds of s->microcode, but i++
allowed one loop too many,

  hw/misc/milkymist-pfpu.c: In function ‘pfpu_write’:
  hw/misc/milkymist-pfpu.c:365:20: error: loop exit may only be reached after undefined behavior [-Werror=aggressive-loop-optimizations]
                   if (i++ >= MICROCODE_WORDS) {
                      ^
  hw/misc/milkymist-pfpu.c:167:14: note: possible undefined statement is here
       uint32_t insn = s->microcode[pc];
                ^

The code can still access out of bounds, because it presumes that PC register
always begins at 0, and we allow writing to it.

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 v2: used a simpler solution [Paolo, Peter]

 hw/misc/milkymist-pfpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/misc/milkymist-pfpu.c b/hw/misc/milkymist-pfpu.c
index 609f33f9cd14..08b604f13f4b 100644
--- a/hw/misc/milkymist-pfpu.c
+++ b/hw/misc/milkymist-pfpu.c
@@ -362,7 +362,7 @@ static void pfpu_start(MilkymistPFPUState *s)
             i = 0;
             while (pfpu_decode_insn(s)) {
                 /* decode at most MICROCODE_WORDS instructions */
-                if (i++ >= MICROCODE_WORDS) {
+                if (++i >= MICROCODE_WORDS) {
                     error_report("milkymist_pfpu: too many instructions "
                             "executed in microcode. No VECTOUT?");
                     break;
-- 
2.3.0

  parent reply	other threads:[~2015-02-20 16:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-20 16:06 [Qemu-devel] [PATCH 0/2] Fix GCC 5.0.0 build errors Radim Krčmář
2015-02-20 16:06 ` [Qemu-devel] [PATCH 1/2] fix GCC 5.0.0 logical-not-parentheses warnings Radim Krčmář
2015-03-04 14:36   ` Michael Tokarev
2015-03-04 16:27     ` Radim Krčmář
2015-02-20 16:06 ` Radim Krčmář [this message]
2015-02-23 17:32   ` [Qemu-devel] [PATCH 2/2] milkymist-pfpu: fix GCC 5.0.0 aggressive-loop-optimizations warning Michael Walle
2015-02-20 17:04 ` [Qemu-devel] [PATCH 0/2] Fix GCC 5.0.0 build errors Radim Krčmář
2015-03-04 14:38 ` Michael Tokarev
  -- strict thread matches above, loose matches on Subject: below --
2015-02-20 14:18 Radim Krčmář
2015-02-20 14:18 ` [Qemu-devel] [PATCH 2/2] milkymist-pfpu: fix GCC 5.0.0 aggressive-loop-optimizations warning Radim Krčmář
2015-02-20 14:24   ` Radim Krčmář
2015-02-20 14:36   ` Paolo Bonzini
2015-02-20 14:52     ` Michael Walle
2015-02-20 14:55       ` Paolo Bonzini
2015-02-20 15:48         ` Radim Krčmář
2015-02-20 14:40   ` Peter Maydell
2015-02-20 15:37     ` Radim Krčmář
2015-02-20 16:10       ` Michael Walle

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=1424448376-15599-3-git-send-email-rkrcmar@redhat.com \
    --to=rkrcmar@redhat.com \
    --cc=michael@walle.cc \
    --cc=pbonzini@redhat.com \
    --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).