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)


Hi,

Jakub Jelinek wrote:
> If using logicals is required to store all the bits of the constants
> (and similarly for TRANSFER from integer to logical), then I'm afraid the
> Fortran FE would have to stop using BOOLEAN_TYPE for logical, as the
> middle-end BOOLEAN_TYPE really has the semantics that it is either false or
> true, nothing else.
>   

According to the standard, what TRANSFER does is implementation
dependent (though one can assume that most of the time the bits are
transferred one-to-one).

In words of the standard: "Result Value. If the physical representation
of the result has the same length as that of SOURCE, the physical
representation of the result is that of SOURCE." The point is: The
standard does not tell what is meant by "physical representation"; I
read it such that the standard does not 100% require that an integer ->
logical -> integer round trip yields the same result. (Though it should
if possible.=

In any case, I don't see any use in doing such round trips - and I also
do not see any use in TRANSFERring anything to logical as it is
completely opaque which bit pattern is regarded as .true. and what as
.false. For instance:

- gfortran (and C) use "== 0" for .false. and "!= 0" for .true. where by
default transfer(.true., 0) == 1.
- Intel's ifort has the same 0 and 1 defaults, but e.g. "2" is FALSE
- (other compilers might have different choices, taking only the
highest/lowest bit, or ...)

(I think TRANSFERring to logical is based on the misconception that
INTEGER and LOGICAL are internally the same data type, similarly to
_Bool and int in C.)

* * *

Regarding Holleriths: They were added in Fortran 66 while LOGICAL exists
since Fortran IV. In Fortran 77 the CHARACTER type was introduced and
Hollerith was deleted from the standard (but it is still listed in
Appendix C). Appendix C has: "Hollerith data, other than constants, are
identified under the guise of a name of type integer, real, or logical."
(See http://gcc.gnu.org/wiki/GFortranStandards for links to the various
Fortran standards.)

Thus that "logical = 4Ho wo" yielding "1" _is_ a problem for certain old
code, though as Holleriths were deleted, this conversion is OK from the
standard perspective.

I assume that by far the most Fortran programs use INTEGER for
Holleriths, but I don't rule out the possibility that some use LOGICAL.

* * *

You see that I'm mainly concerned about Holleriths and less about "(some
type) -> logical -> (some type)" transfers.

I'm wondering whether one needs some special flag to use optionally
internally integers instead of booleans for LOGICAL, with a warning
printed if the option is disabled (as it should be by default) in case a
TRANSFER to a LOGICAL or an assignment of a Hollerith to a logical
variable is found.

But as default I'm in favour to keep the status quo in the front end:
Use the middle end's boolean type for LOGICAL. And I'm in favour of
doing the folding as Jakub's patch does.

Tobias


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