Received: from eggs.gnu.org ([2001:4830:134:3::10]:44714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOq9v-0001yW-JK for qemu-devel@nongnu.org; Fri, 20 Feb 2015 11:10:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YOq9s-0000Nh-4z for qemu-devel@nongnu.org; Fri, 20 Feb 2015 11:10:31 -0500 Received: from ssl.serverraum.org ([88.198.40.39]:57662) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOq9r-0000NZ-Vx for qemu-devel@nongnu.org; Fri, 20 Feb 2015 11:10:28 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Date: Fri, 20 Feb 2015 17:10:26 +0100 From: Michael Walle In-Reply-To: <20150220153748.GB18126@potion.brq.redhat.com> References: <1424441905-5735-1-git-send-email-rkrcmar@redhat.com> <1424441905-5735-3-git-send-email-rkrcmar@redhat.com> <20150220153748.GB18126@potion.brq.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: Peter Maydell , QEMU Developers Am 2015-02-20 16:37, schrieb Radim Kr=C4=8Dm=C3=A1=C5=99: > 2015-02-20 23:40+0900, Peter Maydell: >> On 20 February 2015 at 23:18, Radim Kr=C4=8Dm=C3=A1=C5=99 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 objectiona= ble >> > way, >> > 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 reac= hed after undefined behavior [-Werror=3Daggressive-loop-optimizations] >> > if (i++ >=3D MICROCODE_WORDS) { >> > ^ >> > hw/misc/milkymist-pfpu.c:167:14: note: possible undefined statemen= t is here >> > uint32_t insn =3D s->microcode[pc]; >> > ^ >>=20 >> Why can't we just fix this by fixing the loop boundary >> condition, which is the actual bug here? There should >> be no need to move the check into the function (where it >> does not belong). >=20 > It would work now, but GCC could get more intelligent with time and > realize that there still can be undefined behavior ... >=20 >> (We try to stop before overflowing the s->microcode[] >> array, but because 'i++' is a post increment and we do a >=3D >> comparison, the last loop round will try to write to >> s->microcode[MICROCODE_WORDS]. Easiest fix is to use >> "++i" I suppose, though it might be better to just >> separate the increment and the conditional instead.) >>=20 >> There is probably some actual hardware behaviour we're >> failing to model correctly here, since it's a safe bet >> the h/w doesn't print an error message in this situation. >> However we should just fix the bogus array handling for now. >=20 > Ok, I will do just ++i for v2 and keep the other bug for later. Ok, i'll post a patch later. -michael