public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/34476]  New: Parameters: Bogus out of bounds error in array constructor
@ 2007-12-15  9:14 burnus at gcc dot gnu dot org
  2007-12-15 10:08 ` [Bug fortran/34476] " jv244 at cam dot ac dot uk
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-12-15  9:14 UTC (permalink / raw)
  To: gcc-bugs

The following valid program is rejected with

   integer(1), parameter :: ARR1(len(HEX1)) = [( MSKa1(i), i=1,len(HEX1) )]
                                                      1
Error: index in dimension 1 is out of bounds at (1)

module abuse_mod
   implicit none
   integer i
   character(8), parameter :: HEX1 = '40490FDB'
   integer(1), parameter :: MSKa1(len(HEX1)) =  [(1,i=1,len(HEX1))]
   integer(1), parameter :: ARR1(len(HEX1)) = [( MSKa1(i), i=1,len(HEX1) )]
end module abuse_mod

For a longer example (which uses supported vendor extensions), see:
http://groups.google.com/group/comp.lang.fortran/msg/2499294cb9a33299


-- 
           Summary: Parameters: Bogus out of bounds error in array
                    constructor
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


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


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

* [Bug fortran/34476] Parameters: Bogus out of bounds error in array constructor
  2007-12-15  9:14 [Bug fortran/34476] New: Parameters: Bogus out of bounds error in array constructor burnus at gcc dot gnu dot org
@ 2007-12-15 10:08 ` jv244 at cam dot ac dot uk
  2007-12-17  5:41 ` pault at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jv244 at cam dot ac dot uk @ 2007-12-15 10:08 UTC (permalink / raw)
  To: gcc-bugs



-- 

jv244 at cam dot ac dot uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |32834
              nThis|                            |
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-12-15 10:08:30
               date|                            |


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


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

* [Bug fortran/34476] Parameters: Bogus out of bounds error in array constructor
  2007-12-15  9:14 [Bug fortran/34476] New: Parameters: Bogus out of bounds error in array constructor burnus at gcc dot gnu dot org
  2007-12-15 10:08 ` [Bug fortran/34476] " jv244 at cam dot ac dot uk
@ 2007-12-17  5:41 ` pault at gcc dot gnu dot org
  2007-12-17 15:33 ` w6ws at earthlink dot net
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-12-17  5:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pault at gcc dot gnu dot org  2007-12-17 05:41 -------
4.2 gives a second error:

   integer(1), parameter :: ARR1(len(HEX1)) = [( MSKa1(i), i=1,len(HEX1) )]
                                                      1
Error: index in dimension 1 is out of bounds at (1)
pr34476.f90:5.44:

   integer(1), parameter :: MSKa1(len(HEX1)) =  [(1,i=1,len(HEX1))]
                                           1
Error: Parameter array 'mska1' at (1) cannot be automatic or assumed shape

Paul


-- 


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


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

* [Bug fortran/34476] Parameters: Bogus out of bounds error in array constructor
  2007-12-15  9:14 [Bug fortran/34476] New: Parameters: Bogus out of bounds error in array constructor burnus at gcc dot gnu dot org
  2007-12-15 10:08 ` [Bug fortran/34476] " jv244 at cam dot ac dot uk
  2007-12-17  5:41 ` pault at gcc dot gnu dot org
@ 2007-12-17 15:33 ` w6ws at earthlink dot net
  2007-12-17 22:53 ` pault at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: w6ws at earthlink dot net @ 2007-12-17 15:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from w6ws at earthlink dot net  2007-12-17 15:33 -------
Here is an additional variant of this bug:

program init_bug
  implicit none

  integer :: i
  character(11), parameter :: string="hello world"

! This compiles:
  character, parameter :: up_string(len (string)) =  &
    (/ (string(i:i), i=1, len (string)) /)

  integer, parameter :: bytes(len (string)) =  &
    (/ (iachar (string(i:i)), i=1, len (string)) /)

  integer, parameter :: up_bytes(len (string)) =  &
    (/ (iachar (up_string(i)), i=1, size (up_string)) /)

  print *, string
  print *, up_string

  print *, bytes
  print *, up_bytes

end program

Besides the out-of-bounds error, it also gives a 'cannot appear in the
expression error':


    (/ (iachar (up_string(i)), i=1, size (up_string)) /)
                         1
Error: index in dimension 1 is out of bounds at (1)
abuse_init4.f90:12.25:

    (/ (iachar (string(i:i)), i=1, len (string)) /)
                        1
Error: Variable 'i' cannot appear in the expression at (1)
abuse_init4.f90:21.19:

  print *, up_bytes
                  1
Error: Symbol 'up_bytes' at (1) has no IMPLICIT type


-- 

w6ws at earthlink dot net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |w6ws at earthlink dot net


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


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

* [Bug fortran/34476] Parameters: Bogus out of bounds error in array constructor
  2007-12-15  9:14 [Bug fortran/34476] New: Parameters: Bogus out of bounds error in array constructor burnus at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2007-12-17 15:33 ` w6ws at earthlink dot net
@ 2007-12-17 22:53 ` pault at gcc dot gnu dot org
  2008-01-08 12:16 ` pault at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-12-17 22:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pault at gcc dot gnu dot org  2007-12-17 22:53 -------
The first part of this PR is fixed with:

Index: gcc/fortran/expr.c
===================================================================
*** gcc/fortran/expr.c  (revision 130811)
--- gcc/fortran/expr.c  (working copy)
*************** find_array_element (gfc_constructor *con
*** 1026,1035 ****
        }

        /* Check the bounds.  */
!       if (ar->as->upper[i]
!         && (mpz_cmp (e->value.integer, ar->as->upper[i]->value.integer) > 0
!             || mpz_cmp (e->value.integer,
!                         ar->as->lower[i]->value.integer) < 0))
        {
          gfc_error ("index in dimension %d is out of bounds "
                     "at %L", i + 1, &ar->c_where[i]);
--- 1026,1039 ----
        }

        /* Check the bounds.  */
!       if ((ar->as->upper[i]
!            && ar->as->upper[i]->expr_type == EXPR_CONSTANT
!            && mpz_cmp (e->value.integer,
!                        ar->as->upper[i]->value.integer) > 0)
!               ||
!         (ar->as->lower[i]->expr_type == EXPR_CONSTANT
!            && mpz_cmp (e->value.integer,
!                        ar->as->lower[i]->value.integer) < 0))
        {
          gfc_error ("index in dimension %d is out of bounds "
                     "at %L", i + 1, &ar->c_where[i]);

The second is due to the gfc_error at expr.c(check_restricted):2495

There is some attribute that 'i' has which should make it an exception - I just
do not quite see what it is right now.

Paul


-- 

pault at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |pault at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2007-12-15 10:08:30         |2007-12-17 22:53:09
               date|                            |


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


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

* [Bug fortran/34476] Parameters: Bogus out of bounds error in array constructor
  2007-12-15  9:14 [Bug fortran/34476] New: Parameters: Bogus out of bounds error in array constructor burnus at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2007-12-17 22:53 ` pault at gcc dot gnu dot org
@ 2008-01-08 12:16 ` pault at gcc dot gnu dot org
  2008-01-08 15:45 ` pault at gcc dot gnu dot org
  2008-01-08 16:07 ` pault at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-01-08 12:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pault at gcc dot gnu dot org  2008-01-08 10:31 -------
Created an attachment (id=14898)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14898&action=view)
A fix  and testcase for this PR

This is regtesting right now.

Paul


-- 


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


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

* [Bug fortran/34476] Parameters: Bogus out of bounds error in array constructor
  2007-12-15  9:14 [Bug fortran/34476] New: Parameters: Bogus out of bounds error in array constructor burnus at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2008-01-08 12:16 ` pault at gcc dot gnu dot org
@ 2008-01-08 15:45 ` pault at gcc dot gnu dot org
  2008-01-08 16:07 ` pault at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-01-08 15:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pault at gcc dot gnu dot org  2008-01-08 15:15 -------
Subject: Bug 34476

Author: pault
Date: Tue Jan  8 15:14:33 2008
New Revision: 131396

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131396
Log:
2008-01-08  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/34476
        * expr.c (find_array_element): Check that the array bounds are
        constant before using them.  Use lower, as well as upper bound.
        (check_restricted): Allow implied index variable.

2008-01-08  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/34476
        * gfortran.dg/parameter_array_init_3.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/parameter_array_init_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/34476] Parameters: Bogus out of bounds error in array constructor
  2007-12-15  9:14 [Bug fortran/34476] New: Parameters: Bogus out of bounds error in array constructor burnus at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2008-01-08 15:45 ` pault at gcc dot gnu dot org
@ 2008-01-08 16:07 ` pault at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-01-08 16:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pault at gcc dot gnu dot org  2008-01-08 15:16 -------
Fixed on trunk

Paul


-- 

pault at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2008-01-08 15:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-15  9:14 [Bug fortran/34476] New: Parameters: Bogus out of bounds error in array constructor burnus at gcc dot gnu dot org
2007-12-15 10:08 ` [Bug fortran/34476] " jv244 at cam dot ac dot uk
2007-12-17  5:41 ` pault at gcc dot gnu dot org
2007-12-17 15:33 ` w6ws at earthlink dot net
2007-12-17 22:53 ` pault at gcc dot gnu dot org
2008-01-08 12:16 ` pault at gcc dot gnu dot org
2008-01-08 15:45 ` pault at gcc dot gnu dot org
2008-01-08 16:07 ` pault at gcc dot gnu dot 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).