From: Michael Walle <michael@walle.cc>
To: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH 2/2] milkymist-pfpu: fix GCC 5.0.0 aggressive-loop-optimizations warning
Date: Fri, 20 Feb 2015 17:10:26 +0100 [thread overview]
Message-ID: <b912a6cfba3082d8352a83fb6bd0a95d@walle.cc> (raw)
In-Reply-To: <20150220153748.GB18126@potion.brq.redhat.com>
Am 2015-02-20 16:37, schrieb Radim Krčmář:
> 2015-02-20 23:40+0900, Peter Maydell:
>> On 20 February 2015 at 23:18, Radim Krčmář <rkrcmar@redhat.com> 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];
>> > ^
>>
>> 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).
>
> It would work now, but GCC could get more intelligent with time and
> realize that there still can be undefined behavior ...
>
>> (We try to stop before overflowing the s->microcode[]
>> array, but because 'i++' is a post increment and we do a >=
>> 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.)
>>
>> 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.
>
> Ok, I will do just ++i for v2 and keep the other bug for later.
Ok, i'll post a patch later.
-michael
next prev parent reply other threads:[~2015-02-20 16:10 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-20 14:18 [Qemu-devel] [PATCH 0/2] Fix GCC 5.0.0 build errors Radim Krčmář
2015-02-20 14:18 ` [Qemu-devel] [PATCH 1/2] fix GCC 5.0.0 logical-not-parentheses warnings Radim Krčmář
2015-02-20 14:38 ` Paolo Bonzini
2015-02-20 15:43 ` 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 [this message]
-- strict thread matches above, loose matches on Subject: below --
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 2/2] milkymist-pfpu: fix GCC 5.0.0 aggressive-loop-optimizations warning Radim Krčmář
2015-02-23 17:32 ` 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=b912a6cfba3082d8352a83fb6bd0a95d@walle.cc \
--to=michael@walle.cc \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rkrcmar@redhat.com \
/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).