From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOogs-0002Te-Gs for qemu-devel@nongnu.org; Fri, 20 Feb 2015 09:36:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YOogo-00046f-0h for qemu-devel@nongnu.org; Fri, 20 Feb 2015 09:36:26 -0500 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:44183) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOogn-00046W-Qd for qemu-devel@nongnu.org; Fri, 20 Feb 2015 09:36:21 -0500 Received: by mail-wi0-f178.google.com with SMTP id em10so3324216wid.5 for ; Fri, 20 Feb 2015 06:36:21 -0800 (PST) Sender: Paolo Bonzini Message-ID: <54E74662.5090203@redhat.com> Date: Fri, 20 Feb 2015 15:36:18 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1424441905-5735-1-git-send-email-rkrcmar@redhat.com> <1424441905-5735-3-git-send-email-rkrcmar@redhat.com> In-Reply-To: <1424441905-5735-3-git-send-email-rkrcmar@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 2/2] milkymist-pfpu: fix GCC 5.0.0 aggressive-loop-optimizations warning List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , qemu-devel@nongnu.org Cc: Michael Walle On 20/02/2015 15:18, Radim Krčmář wrote: > 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. > > Refactored the code a bit to avoid the GCC warning, in an objectionable > way, > 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]; > ^ > > Signed-off-by: Radim Krčmář > --- > hw/misc/milkymist-pfpu.c | 18 ++++++++---------- > 1 file changed, 8 insertions(+), 10 deletions(-) > > diff --git a/hw/misc/milkymist-pfpu.c b/hw/misc/milkymist-pfpu.c > index 609f33f9cd14..133f5b8c5153 100644 > --- a/hw/misc/milkymist-pfpu.c > +++ b/hw/misc/milkymist-pfpu.c > @@ -164,6 +164,13 @@ output_queue_advance(MilkymistPFPUState *s) > static int pfpu_decode_insn(MilkymistPFPUState *s) > { > uint32_t pc = s->regs[R_PC]; > + > + if (pc > MICROCODE_WORDS) { > + error_report("milkymist_pfpu: too many instructions " > + "executed in microcode. No VECTOUT?"); > + return 0; > + } > + > uint32_t insn = s->microcode[pc]; > uint32_t reg_a = (insn >> 18) & 0x7f; > uint32_t reg_b = (insn >> 11) & 0x7f; > @@ -348,7 +355,6 @@ static int pfpu_decode_insn(MilkymistPFPUState *s) > static void pfpu_start(MilkymistPFPUState *s) > { > int x, y; > - int i; > > for (y = 0; y <= s->regs[R_VMESHLAST]; y++) { > for (x = 0; x <= s->regs[R_HMESHLAST]; x++) { > @@ -359,15 +365,7 @@ static void pfpu_start(MilkymistPFPUState *s) > s->gp_regs[GPR_Y] = y; > > /* run microcode on this position */ > - i = 0; > - while (pfpu_decode_insn(s)) { > - /* decode at most MICROCODE_WORDS instructions */ > - if (i++ >= MICROCODE_WORDS) { Isn't the fix just to say "++i" instead of "i++"? Paolo > - error_report("milkymist_pfpu: too many instructions " > - "executed in microcode. No VECTOUT?"); > - break; > - } > - } > + while (pfpu_decode_insn(s)); > > /* reset pc for next run */ > s->regs[R_PC] = 0; >