This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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] Fold VIEW_CONVERT_EXPR <type, STRING_CST> generated by Fortran FE a lot (PR target/35366)


On Tue, Nov 11, 2008 at 19:49, Jakub Jelinek <jakub@redhat.com> wrote:
> On Tue, Nov 11, 2008 at 06:01:52PM +0100, Tobias Schlüter wrote:
>> Jakub Jelinek wrote:
>>> On Tue, Nov 11, 2008 at 05:21:36PM +0100, Tobias Schlüter wrote:
>>>> Hm, I haven't found Richard Maine's post that is mentioned in the old
>>>>  thread, but Fortran has the notion of storage unit.  LOGICAL*4,
>>>> INTEGER*4 and REAL*4 all occupy 4 storage units.  If a circular
>>>> transfer(transfer (...) ...) between types with the same number of
>>>> storage units is required to return the original value (as Richard
>>>> Maine  apparently argued), then we'll probably have no choice but to
>>>> stop using  BOOLEAN_TYPE for LOGICALs.
>>>
>>> That's pretty sad.  Stopping using BOOLEAN_TYPE is going to break
>>> basically everything, so certainly can't be done for 4.4.  I expect
>>> that you'd need to add a lot of conversions everywhere, from the
>>> logical*N INTEGER_TYPE to correspondingly sized BOOLEAN_TYPE and back
>>> all the time.
>>
>> Maybe setting TYPE_PRECISION to bit_size in gfc_build_logical_type()
>> would do the trick without any further changes?  This depends on how the
>> middle-end deals with BOOLEAN_TYPES with TYPE_PRECISION > 1.
>
> It wouldn't help:
>
> /* Boolean type (true or false are the only values).  Looks like an
>   INTEGRAL_TYPE.  */
> DEFTREECODE (BOOLEAN_TYPE, "boolean_type", tcc_type, 0)
>
> On the other side, if you have to convert from INTEGER_TYPE to BOOLEAN_TYPE
> all the time, the generated code will be very abysmal.
>
> How is LOGICAL supposed to behave if it is storage associated with an
> integer?  Defined only if the integer stored has been 0 or 1, or 0 .false.
> and non-zero .true., or something else?

The standard doesn't specify what is the internal representation of
logical values, other than that the size of default LOGICAL is the
same as other types of default kind.  If you search on google groups
for "Richard Maine transfer logical" you'll find the threads "Transfer
and variables that don't use all their storage space." and "Trying to
use a logical as an array index" with arguments about this point
(Richard Maine was the editor of the Fortran 2003 standard, so he
generally knows what he's talking about).

The loophole seems to be that if the transfer generates an illegal
value, then the program becomes non-standard and the compiler can do
whatever it wants.

I.e. while the point of transfer is more or less to do type-punning
via straight-forward copying of bits, the resulting bit patterns must
be a valid bit pattern for the type in question if the program is to
be standard-conforming.

-- 
Janne Blomqvist


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