[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gm2] parameter range value overflow detected and integer division overf
From: |
Gaius Mulley |
Subject: |
[Gm2] parameter range value overflow detected and integer division overflow |
Date: |
Mon, 24 Jun 2019 11:28:18 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Hi,
I'm almost about to push some changes to the trunk which will:
(*) detect integer overflow with ordinal operands.
(Only div trunc currently -fpim2 -fpim3). When I finish
div ceil and div floor then -fpim4 and -fiso division will be
fully detected. I think the only remaining operator after this
is modulus. At that point all ordinal arithmetic overflow
should be detected.
(*) detect parameter range value overflow. For example see the
following example. Hopefully this additional check could be
quite useful.
both tests will generate runtime checking code. Both tests can also
under certain conditions be detected at compile time with the Modula-2
plugin (automatically run when gm2 is used).
Here it is in action:
$ cat overflow2.mod
MODULE overflow2 ;
FROM libc IMPORT printf ;
PROCEDURE func (x, y: CARDINAL) ;
VAR
res: CARDINAL ;
BEGIN
res := x DIV y ;
printf ("res = %ud\n", res);
END func ;
VAR
x, y: INTEGER ;
u : CARDINAL ;
BEGIN
x := 1 ;
y := -1 ;
func (x, y) ;
END overflow2.
$ gm2 -O2 -fsoft-check-all overflow2.mod
overflow2.mod:20:3:inevitable runtime error will occur, an exception
will occur because the actual parameter is out of range of the formal
parameter
the message should be improved to say which parameter and maybe the
limits of the type. But at least the detection logic is working :-)
regards,
Gaius
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gm2] parameter range value overflow detected and integer division overflow,
Gaius Mulley <=