[fpc-devel] bug: Inc(v,i)/Dec(v,i)
Gerhard Scholz
gs at g--s.de
Mon Jul 4 15:13:08 CEST 2005
I've tried to submit this as a bug report, but after pressing on "Submit bug"
nothing happens on http://www.freepascal.org/bugs/add.php3
Inc ( v, i ) and Dec ( v, i ) produce rangecheck or overflow check with {$r+,q+}
Without checks the program runs corrctly.
The values and results are in range; the errors shold not occur.
Example program:
{$r+,q+,s+}
{ $r-,q-,s-}
program incdec ;
uses
sysutils ;
var
pre : 0..132 ;
fra : -132..132 ;
procedure init ; begin pre := 1 ; fra := -1 ; end ;
begin
init ; pre := pre + fra ; writeln ( pre ) ;
init ; pre := pre - fra ; writeln ( pre ) ;
init ; inc ( pre, fra ) ; {Dec/Inc error? } writeln ( pre ) ;
init ; Dec ( pre, fra ) ; {Dec/Inc error? } writeln ( pre ) ;
end.
The assembler code shows that Inc/Dec assumes that the second parameter
has the same type as the first. This is not true in this case.
Assembler code (shortened):
#...
# [18] init ; pre := pre + fra ; writeln ( pre ) ;
call P$INCDEC_INIT
movzbl U_P$INCDEC_PRE,%eax
movswl U_P$INCDEC_FRA,%edx
addl %eax,%edx
jno .L18
call FPC_OVERFLOW
.L18:
movl %edx,%eax
cmpl $132,%eax
jbe .L19
call FPC_RANGEERROR
.L19:
movb %dl,U_P$INCDEC_PRE
#...
# [19] init ; pre := pre - fra ; writeln ( pre ) ;
call P$INCDEC_INIT
movzbl U_P$INCDEC_PRE,%edx
movswl U_P$INCDEC_FRA,%eax
subl %eax,%edx
jno .L32
call FPC_OVERFLOW
.L32:
movl %edx,%eax
cmpl $132,%eax
jbe .L33
call FPC_RANGEERROR
.L33:
movb %dl,U_P$INCDEC_PRE
#...
# [20] init ; inc ( pre, fra ) ; {Dec/Inc error? } writeln ( pre ) ;
call P$INCDEC_INIT
movzbl U_P$INCDEC_PRE,%eax
movzbl U_P$INCDEC_FRA,%edx
addl %eax,%edx
jae .L46
call FPC_OVERFLOW
.L46:
movl %edx,%eax
cmpl $132,%eax
jbe .L47
call FPC_RANGEERROR
.L47:
#...
movb %dl,U_P$INCDEC_PRE
# [21] init ; Dec ( pre, fra ) ; {Dec/Inc error? } writeln ( pre ) ;
call P$INCDEC_INIT
movzbl U_P$INCDEC_PRE,%edx
movzbl U_P$INCDEC_FRA,%eax
subl %eax,%edx
jae .L60
call FPC_OVERFLOW
.L60:
movl %edx,%eax
cmpl $132,%eax
jbe .L61
call FPC_RANGEERROR
.L61:
#...
More information about the fpc-devel
mailing list