Bad code generated for the Case statement in some circumstances
Original Reporter info from Mantis: chastai
-
Reporter name: Christophe Staïesse
Original Reporter info from Mantis: chastai
- Reporter name: Christophe Staïesse
Description:
Hello,
The code generated for the Case statement is sometime incorrect when the constants are unsigned integers. This bug appears in the latest build (2012/12/17) but not in 2.6.0.
For example :
case byte(2) of
1: writeln('1');
2,3: writeln('2 or 3');
end;
generates:
... # [2] case byte(2) of movb $2,%al cmpb $1,%al jb .Lj4 decb %al je .Lj5 * decb %al * jb .Lj4 subb $1,%al jbe .Lj6 jmp .Lj4 ...
The instructions marked with an asterisk test if the choice variable is below 2. The problem is that DEC don't touch to the carry flag, so the JB test is wrong.
It doesn't harm in this example as CF is clear when these instructions are reached.
Steps to reproduce:
I've attached a program that will print 'Bug!' if the bug was detected.
It sets explicitely the carry flag and it is still set when the badly generated instructions are executed.
Mantis conversion info:
- Mantis ID: 23503
- OS: Linux
- Build: 2012/12/17
- Platform: X86_64
- Version: 2.7.1
- Fixed in version: 3.0.0
- Fixed in revision: 23229 (#feefcb6d)