[fpc-devel] Division nodes

Stefan Glienke sglienke at dsharp.org
Tue May 16 01:43:44 CEST 2023


FWIW in 3.2.2 I don't see the -1 check and the idiv causes an int overflow exception. But silently returning 0 for min_int div -1 feels very wrong imo.

> On 15/05/2023 18:43 CEST Kirinn via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
> 
>  
> I didn't see a mention of it in this discussion thread, but dividing the
> largest negative integer by -1 does cause an overflow error of some sort,
> because of two's complement.
> 
> Just to make sure, do (min_int div -1) and (min_int mod -1) behave the same
> way before and after this proposed change? And, what min_int is of course
> depends on whether targeting a 32-bit or 64-bit system, so best check both
> cases.
> 
> ~Kirinn
> 
> On Mon, 15 May 2023 17:21:30 +0100
> "J. Gareth Moreton via fpc-devel" <fpc-devel at lists.freepascal.org> wrote:
> 
> > I made a merge request that removes the comparison against -1. 
> > x86_64-win64 and i386-win32 pass without any regressions, so the reason 
> > behind the change still eludes me.  Maybe my fix for #39646 removes the 
> > need for it?
> > 
> > https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/418
> > 
> > Kit
> > 
> > On 11/05/2023 23:04, J. Gareth Moreton via fpc-devel wrote:
> > > Fair enough, but I would like an explanation as to why it's necessary, 
> > > because the reason for testing -1 in particular is very unclear, and I 
> > > wonder if there's a known misbehaviour with a particular division 
> > > function with -1.
> > >
> > > Kit
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


More information about the fpc-devel mailing list