public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/50753] New: dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ
@ 2011-10-17  6:52 burnus at gcc dot gnu.org
  2011-10-27 15:50 ` [Bug fortran/50753] " kargl at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-10-17  6:52 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50753

             Bug #: 50753
           Summary: dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid, rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org
                CC: kargl@gcc.gnu.org


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'

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."

 * * *

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.)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/50753] dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ
  2011-10-17  6:52 [Bug fortran/50753] New: dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ burnus at gcc dot gnu.org
@ 2011-10-27 15:50 ` kargl at gcc dot gnu.org
  2011-10-27 15:57 ` sgk at troutmask dot apl.washington.edu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: kargl at gcc dot gnu.org @ 2011-10-27 15:50 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/50753] dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ
  2011-10-17  6:52 [Bug fortran/50753] New: dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ burnus at gcc dot gnu.org
  2011-10-27 15:50 ` [Bug fortran/50753] " kargl at gcc dot gnu.org
@ 2011-10-27 15:57 ` sgk at troutmask dot apl.washington.edu
  2011-10-29 15:18 ` burnus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: sgk at troutmask dot apl.washington.edu @ 2011-10-27 15:57 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50753

--- Comment #2 from Steve Kargl <sgk at troutmask dot apl.washington.edu> 2011-10-27 15:56:35 UTC ---
On Thu, Oct 27, 2011 at 03:49:15PM +0000, kargl at gcc dot gnu.org wrote:
> > 
> > "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)."
> > 

On further inspection of SHIFT in gfc_check_dshift, it seems
that gfortran does not do the 'otherwise, ....' portion of
the above.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/50753] dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ
  2011-10-17  6:52 [Bug fortran/50753] New: dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ burnus at gcc dot gnu.org
  2011-10-27 15:50 ` [Bug fortran/50753] " kargl at gcc dot gnu.org
  2011-10-27 15:57 ` sgk at troutmask dot apl.washington.edu
@ 2011-10-29 15:18 ` burnus at gcc dot gnu.org
  2011-10-30 22:03 ` kargl at gcc dot gnu.org
  2011-10-30 22:10 ` kargl at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-10-29 15:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50753

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-10-29 15:18:28 UTC ---
Submitted patch:
http://gcc.gnu.org/ml/fortran/2011-10/msg00203.html


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/50753] dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ
  2011-10-17  6:52 [Bug fortran/50753] New: dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2011-10-29 15:18 ` burnus at gcc dot gnu.org
@ 2011-10-30 22:03 ` kargl at gcc dot gnu.org
  2011-10-30 22:10 ` kargl at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: kargl at gcc dot gnu.org @ 2011-10-30 22:03 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50753

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.7.0

--- Comment #4 from kargl at gcc dot gnu.org 2011-10-30 22:03:30 UTC ---
Fixed on trunk.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/50753] dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ
  2011-10-17  6:52 [Bug fortran/50753] New: dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2011-10-30 22:03 ` kargl at gcc dot gnu.org
@ 2011-10-30 22:10 ` kargl at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: kargl at gcc dot gnu.org @ 2011-10-30 22:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50753

--- Comment #5 from kargl at gcc dot gnu.org 2011-10-30 22:09:50 UTC ---
Dang.  I transposed numbers in the PR in the ChangeLog.  Here's
the commit message with the correct PR number.

Author: kargl
Date: Sun Oct 30 21:59:24 2011
New Revision: 180686

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=180686
Log:
2011-10-30  Steven G. Kargl  <kargl@gcc.gnu.org>

    PR fortran/50753
    * check.c (gfc_check_dshift): Update argument checking for BOZ.
    Update checking SHIFT against BITSIZE of I or J.
    * intrinsic.texi: Update docs for DSHIFTL and DSHIFTR.

2011-10-30  Steven G. Kargl  <kargl@gcc.gnu.org>

    PR fortran/50753
    * gfortran.dg/dshift_3.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/dshift_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/intrinsic.texi
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-10-30 22:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-17  6:52 [Bug fortran/50753] New: dshiftl/dshiftr: Rejects valid BOZ, accepts double BOZ burnus at gcc dot gnu.org
2011-10-27 15:50 ` [Bug fortran/50753] " kargl at gcc dot gnu.org
2011-10-27 15:57 ` sgk at troutmask dot apl.washington.edu
2011-10-29 15:18 ` burnus at gcc dot gnu.org
2011-10-30 22:03 ` kargl at gcc dot gnu.org
2011-10-30 22:10 ` kargl at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).