Received: from eggs.gnu.org ([2001:4830:134:3::10]:37157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPwsR-0003UC-4R for qemu-devel@nongnu.org; Mon, 23 Feb 2015 12:33:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YPwsN-0006yM-Rt for qemu-devel@nongnu.org; Mon, 23 Feb 2015 12:33:03 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Date: Mon, 23 Feb 2015 18:32:57 +0100 From: Michael Walle In-Reply-To: <1424448376-15599-3-git-send-email-rkrcmar@redhat.com> References: <1424448376-15599-1-git-send-email-rkrcmar@redhat.com> <1424448376-15599-3-git-send-email-rkrcmar@redhat.com> Message-ID: Content-Transfer-Encoding: quoted-printable 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?Q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= Cc: qemu-trivial@nongnu.org, Paolo Bonzini , qemu-devel@nongnu.org, Peter Maydell Am 2015-02-20 17:06, schrieb Radim Kr=C4=8Dm=C3=A1=C5=99: > 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. >=20 > Milkymist pfpu has no jump instructions, so checking for=20 > MICROCODE_WORDS > instructions should have kept us in bounds of s->microcode, but i++ > allowed one loop too many, >=20 > hw/misc/milkymist-pfpu.c: In function =E2=80=98pfpu_write=E2=80=99: > hw/misc/milkymist-pfpu.c:365:20: error: loop exit may only be > reached after undefined behavior > [-Werror=3Daggressive-loop-optimizations] > if (i++ >=3D MICROCODE_WORDS) { > ^ > hw/misc/milkymist-pfpu.c:167:14: note: possible undefined statement=20 > is here > uint32_t insn =3D s->microcode[pc]; > ^ >=20 > The code can still access out of bounds, because it presumes that PC=20 > register > always begins at 0, and we allow writing to it. >=20 > Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 > --- > v2: used a simpler solution [Paolo, Peter] >=20 > hw/misc/milkymist-pfpu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > 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 =3D 0; > while (pfpu_decode_insn(s)) { > /* decode at most MICROCODE_WORDS instructions */ > - if (i++ >=3D MICROCODE_WORDS) { > + if (++i >=3D MICROCODE_WORDS) { > error_report("milkymist_pfpu: too many=20 > instructions " > "executed in microcode. No VECTOUT?"); > break; Acked-by: Michael Walle