range check 32-bit and 64-bit
ferrallc at queensu.ca
Tue Apr 10 00:04:52 CEST 2007
The following program behaves differently under 32-bit and 64-bit
compilation. In 64-bit the "max()" function returns a large integer
when a value is sent out of bounds (output not shown). The point of the
max() is to keep a value from going out of bounds. This problem does
not occur in 32-bit code. To make sure that range checking was on in
both cases I set "a" out of range after the max().
Is this a feature of the cpu option? And/or is there a more robust way
of keeping within range?
Thanks for any help.
P.S. I've already received the following response from Frank.
> I'm not using a 64 bit machine myself, so I can only speculate. I
> hope Waldek can say more about it.
> I think the problem might be that GPC treats "arange" internally as
> an unsigned type (i.e., as a subrange of "Cardinal", not "Integer")
> and on the 64 bit machine performs the "a - 1" unsigned which causes
> the range error. (On the 32 bit machine it can do it in LongestInt
> which covers the range of "Cardinal" as well as negative values, but
> on 64 bit, it currently doesn't support larger integer types. This
> might explain the different behaviour.)
> Of course, this is a GPC bug as, according to ISO, your program is
> perfectly valid (given a suitable definition of "Max" which isn't
> part of ISO).
> So the bugfix might be to make subrange types signed when the range
> allows (which would always be the case in valid ISO programs).
type arange = 0..5;
var a,b : arange;
b := max(a-1,0); /* keep b in range */
writeln('here ',b,' now really go out of range ');
a := b-1; /* take a out of range to make sure
range checking is on */
here 0 now really go out of range
a.out: value out of range (error #300 at 180e3)
a.out: value out of range (error #300 at 100009d2b)
gpc $g64pth $m64opt maxtest.pas
where $m64opt= "-mcpu=ultrasparc3 -m64"
Here is the version output
hpc1014 at sfnode0$ gpc -v
Reading specs from
Configured with: ../gcc-3.4.3/configure --prefix=/opt/gpc/20051104
Thread model: posix
gpc version 20051104, based on gcc-3.4.3
Christopher Ferrall <http://econ.queensu.ca/%7Eferrall/>
Associate Professor of Economics
Department of Economics <http://www.econ.queensu.ca>
Queen's University <http://www.queensu.ca>
CANADA K7L 3N6 ferrallc AT post.queensu.ca
Mackintosh-Corry Rm A519
More information about the Gpc