[fpc-devel] overflow checking

Vincent Snijders vsnijders at quicknet.nl
Mon Mar 26 00:02:07 CEST 2007


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



More information about the fpc-devel mailing list