Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2007-03

overflow checking

2 messages · 1 person · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Vincent Snijders

Hi,

I am trying to compile and run some parts of Lazarus (lcl\interfaces\win32) with -Criot. I get some overflow errors I don't understand. I tried to understand the logic behind the generated assembler and made a small test program, which doesn't give an overflow error, but that has the same (AFAICS) wrong assembler. I am using fpc 2.3.1.

Pascal code:
program Project1;
{$mode objfpc}{$H+}
const
   WAIT_OBJECT_0 = 0;
var
   retVal : dword;
   FWaitHandleCount: dword;
begin
   retVal := 258;
   FWaitHandleCount := 0;
   if retVal = WAIT_OBJECT_0 + FWaitHandleCount then
     writeln('OK');
   readln;
end.

Generated assembler:
.Ll3:
# [14] FWaitHandleCount := 0;
movl $0,U_P$PROJECT1_FWAITHANDLECOUNT
.stabn 68,0,15,.Ll4 - _main
.Ll4:
# [15] if retVal = WAIT_OBJECT_0 + FWaitHandleCount then movl U_P$PROJECT1_FWAITHANDLECOUNT,%eax
jnb .Lj9
call FPC_OVERFLOW
.Lj9:
cmpl U_P$PROJECT1_RETVAL,%eax
je .Lj7
jmp .Lj8

Why is there an overflow check ?
What can set the carry flag used by the jnb?

If I change

   if retVal = WAIT_OBJECT_0 + FWaitHandleCount then

to

   if retVal = FWaitHandleCount then

then there is no overflow check.

Vincent

Reply by email

Vincent Snijders
to Vincent Snijders
Vincent Snijders wrote 8 lines
Hi, I am trying to compile and run some parts of Lazarus (lcl\interfaces\win32) with -Criot. I get some overflow errors I don't understand. I tried to understand the logic behind the generated assembler and made a small test program, which doesn't give an overflow error, but that has the same (AFAICS) wrong assembler. I am using fpc 2.3.1.

I think this is a bug in the compiler, so I created a bug report: http://www.freepascal.org/mantis/view.php?id=8573

Vincent

Reply by email