Received: from eggs.gnu.org ([2001:4830:134:3::10]:51026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTzIc-0007xa-7O for qemu-devel@nongnu.org; Fri, 06 Mar 2015 15:56:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTzIS-0004tF-Nf for qemu-devel@nongnu.org; Fri, 06 Mar 2015 15:56:46 -0500 Received: from isrv.corpit.ru ([86.62.121.231]:33861) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTzIS-0004sy-Gd for qemu-devel@nongnu.org; Fri, 06 Mar 2015 15:56:36 -0500 From: Michael Tokarev Date: Fri, 6 Mar 2015 23:19:28 +0300 Message-Id: <1425673176-9819-50-git-send-email-mjt@msgid.tls.msk.ru> In-Reply-To: <1425673176-9819-1-git-send-email-mjt@tls.msk.ru> References: <1425673176-9819-1-git-send-email-mjt@tls.msk.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 43/51] milkymist-pfpu: fix GCC 5.0.0 aggressive-loop-optimizations warning List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Aneesh Kumar K.V" Cc: Michael Tokarev , qemu-devel@nongnu.org, =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= From: 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. 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 =E2=80=98pfpu_write=E2=80=99: hw/misc/milkymist-pfpu.c:365:20: error: loop exit may only be reached a= fter undefined behavior [-Werror=3Daggressive-loop-optimizations] if (i++ >=3D MICROCODE_WORDS) { ^ hw/misc/milkymist-pfpu.c:167:14: note: possible undefined statement is = here uint32_t insn =3D s->microcode[pc]; ^ The code can still access out of bounds, because it presumes that PC regi= ster always begins at 0, and we allow writing to it. Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 Acked-by: Michael Walle Signed-off-by: Michael Tokarev --- 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 609f33f..08b604f 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 instructions = " "executed in microcode. No VECTOUT?"); break; --=20 2.1.4