milkymist-pfpu: fix GCC 5.0.0 aggressive-loop-optimizations warning
commitc6dc3dd72b747a057770087998a1f9ef0b3f1882
authorRadim Krčmář <rkrcmar@redhat.com>
Fri, 20 Feb 2015 16:06:16 +0000 (20 17:06 +0100)
committerMichael Tokarev <mjt@tls.msk.ru>
Tue, 10 Mar 2015 05:15:34 +0000 (10 08:15 +0300)
tree75208113dd9cc96cb2a1b4b132e8807235bcf3c9
parent8c1ac475e30091ba77a075d5e2136ece4f7c9cd0
milkymist-pfpu: fix GCC 5.0.0 aggressive-loop-optimizations warning

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 ‘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];
                ^

The code can still access out of bounds, because it presumes that PC register
always begins at 0, and we allow writing to it.

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
Acked-by: Michael Walle <michael@walle.cc>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
hw/misc/milkymist-pfpu.c