[Bug fortran/50753] dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ
kargl at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Oct 27 15:50:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50753
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot |kargl at gcc dot gnu.org
|gnu.org |
--- Comment #1 from kargl at gcc dot gnu.org 2011-10-27 15:49:15 UTC ---
(In reply to comment #0)
> Found when checking PR fortran/50514:
>
> gfortran rejects:
>
> integer :: I, J
> print *, dshiftl(z'FFF', J, (bit_size(j)+1))
> end
>
> with
> Error: 'j' argument of 'dshiftl' intrinsic at (1) must
> be the same type and kind as 'i'
I think that this diagnostic is correct [1]. A BOZ is translated
into an integer with the largest kind type parameter. On some
systems that is INTEGER(8) and on others it is INTEGER(16).
Neither is a default integer. On i686-*-freebsd, I get
laptop:kargl[210] cat a.f90
integer(8) :: I, J
print *, dshiftl(z'FFF', J, (bit_size(j)+1))
end
laptop:kargl[211] gfc4x -o z a.f90
a.f90:2.31:
print *, dshiftl(z'FFF', J, (bit_size(j)+1))
1
Error: 'SHIFT' at (1) must be less than or equal to BIT_SIZE('I')
So, the BOZ is accepted, and the error you were trying to generate
is seen.
> Expected:
> a) The BOZ is accepted
> b) There is a diagnostic as SHIFT is larger than BIT_SIZE(J).
>
>
> The same applies to DSHIFTR.
>
>
> From Fortran 2008's 13.7.50 DSHIFTL (I, J, SHIFT)
>
> "Arguments.
>
> I shall be of type integer or a boz-literal-constant.
> J shall be of type integer or a boz-literal-constant. If both I and J are
> of type integer, they shall have the same kind type parameter. I and J
> shall not both be boz-literal-constants.
> SHIFT shall be of type integer. It shall be nonnegative and less than
> or equal to BIT SIZE (I) if I is of type integer; otherwise, it shall
> be less than or equal to BIT SIZE (J)."
>
> Result Value. If either I or J is a boz-literal-constant, it is first
> converted as if by the intrinsic function INT to type integer with the kind
> type parameter of the other."
[1] Crude, just read this part!
OK, in gfc_check_dshift, one has
if (same_type_check (i, 0, j, 1) == FAILURE)
return FAILURE;
which will need to be changed to do the conversion. The psuedo-code
would be something like
if (i_is_boz == true && j_is_boz == true)
error
else if (i_is_boz == true)
convert boz to int
convert int type to j type
else if (j_is_boz == true)
same as above with j <--> i
else if (same_type == false)
error.
> * * *
>
> Additionally, the following is accepted but invalid: Only one BOZ is allowed:
>
> print *, dshiftl(z'FFF', z'AAA', 0)
> end
>
> I am not sure whether it should be allowed with -std=gnu, but none of my
> compilers diagnoses it correctly. (Well, except for ifort, which even rejects
> the example of the Fortran 2008 standard.)
Since this is new in F2008, I think gfortran should follow the
standard; and, not allow this under -std=gnu. There is no need
for backwards compatibility.
--
steve
More information about the Gcc-bugs
mailing list