Skip to content

Commit

Permalink
milkymist-pfpu: fix GCC 5.0.0 aggressive-loop-optimizations warning
Browse files Browse the repository at this point in the history
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ář <[email protected]>
Acked-by: Michael Walle <[email protected]>
Signed-off-by: Michael Tokarev <[email protected]>
  • Loading branch information
rkrcmar authored and Michael Tokarev committed Mar 10, 2015
1 parent 8c1ac47 commit c6dc3dd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion hw/misc/milkymist-pfpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static void pfpu_start(MilkymistPFPUState *s)
i = 0;
while (pfpu_decode_insn(s)) {
/* decode at most MICROCODE_WORDS instructions */
if (i++ >= MICROCODE_WORDS) {
if (++i >= MICROCODE_WORDS) {
error_report("milkymist_pfpu: too many instructions "
"executed in microcode. No VECTOUT?");
break;
Expand Down

0 comments on commit c6dc3dd

Please sign in to comment.