[Patch, Fortran] Fix integer kind returned by storage_size (was: Re: incorrect integer kind returned from call to storage_size() with gcc 4.9.0)

Tobias Burnus burnus@net-b.de
Fri Jul 25 18:16:00 GMT 2014


Hi,

N.M. Maclaren wrote:
> On Jul 25 2014, Rezny, Mike wrote:
>>
>> I am seeing the following problems in using the Fortran intrinsic 
>> function, storage_size(), in gfortran version 4.9.0. 1: A calls to 
>> this function is returning a 64-bit integer instead of a default 
>> 32-bit integer 2: the routine is not honouring the second parameter 
>> to the call which specifies the kind of the returned value. In all 
>> valid cases, the returned value is a 64-bit integer.
>
> The key property is the KIND of the result - if THAT is not KIND(0),
> then there is a bug.

I can confirm the problem. It only occurs when the compiler can simplify 
the intrinsic function call at compile time (what it usually can for 
storage_size). Thus, if one passes a polymorphic argument, the KIND 
value is properly handled. By the way, the used kind is "c_ptrdiff_t" 
from the intrinsic module ISO_C_Binding.

In case a work around is needed, use "int(storage_size(...), kind=...)". 
However, in case you pass the value on to some run-time library, you 
should consider using "integer(c_ptrdiff_t)" [TS 29113] or 
"integer(c_size_t)" [F2003] instead. In general, it makes sense to 
handle as large storage_sizes as the system permits. (ptrdiff_t is 
signed, which matches what Fortran uses as only signed integers are 
supported; size_t is unsigned but of the same storage size; as 
"c_size_t" is already in Fortran 2003 many more compilers support it 
than "c_ptrdiff_t".)


The problem is fixed by the attached patch. I will commit it as obvious 
(to the trunk, i.e. GCC 5 alias GCC 4.10 only) once building and 
regtesting has finished.

Thanks for reporting the bug – and sorry for the inconvenience.

Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: storage_size.diff
Type: text/x-patch
Size: 2664 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20140725/1541e056/attachment.bin>


More information about the Fortran mailing list