This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, fortran] PR32124 - Don't give a run-time error if stat= has been specified for ALLOCATE


At 10:35 AM 5/30/2007, Tobias Burnus wrote:
Brooks Moses wrote:
>> Any ideas? (I knew why I did not want to have a test case when I
>> originally submitted the patch.)
> It would be nice if the runtime library could error out on when the
> size overflows, without needing to rely on the result ending up negative.
I think there are two ways this can happen: (a) at compile time - and
this is what happens here - and (b) at run time. At compile time, we
might be able to create a check whether we are overflowing (this is was
happens here). [I don't know whether there is a simple way of doing so,
maybe a test if negative could be build in? Or is the size argument not
easily accessible in the front end? It is in the dumped original tree.
GMP does not seem to supported.]

For run time, I think there is no easy way. I don't have seen may
systems which offer trapping (SIGFPE) of integer overflows. (There are
some which do, as googling shows.)

I'll have to think about this. There are certainly ways to check and see if a given multiply is going to overflow; yes, they take a couple more operations, but a memory allocation operation is already slow enough that the extra time should be negligible.


For instance, something along the lines of
  if (shape[n] > INT_MAX / stride[n])
should check whether shape[n] * stride[n] will overflow or not.

- Brooks


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]