public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/36112]  New: Bounds-checking on character length not working for array-constructors
@ 2008-05-02 19:05 d at domob dot eu
  2008-05-03  6:15 ` [Bug fortran/36112] " burnus at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: d at domob dot eu @ 2008-05-02 19:05 UTC (permalink / raw)
  To: gcc-bugs

Bounds-checking for correct character length in array-constructors without
F2003 typespec (all strings are required to have the same length) does not work
sometimes, for instance the code

  call test ("this is long")
contains
  subroutine test(s)
    character(len=*) :: s
    character(len=128) :: arr(2)
    arr = (/ s, "abc" /)
  end subroutine test
end

Should give a runtime-error when compiled with "-fbounds-check" and run but it
doesn't; swapping the array constructor to be

arr = (/ "abc", s /)

does, however (which is presumably correct).


-- 
           Summary: Bounds-checking on character length not working for
                    array-constructors
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: d at domob dot eu


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


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

* [Bug fortran/36112] Bounds-checking on character length not working for array-constructors
  2008-05-02 19:05 [Bug fortran/36112] New: Bounds-checking on character length not working for array-constructors d at domob dot eu
@ 2008-05-03  6:15 ` burnus at gcc dot gnu dot org
  2008-05-03 13:32 ` d at domob dot eu
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-05-03  6:15 UTC (permalink / raw)
  To: gcc-bugs



-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |27766
              nThis|                            |
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2008-05-03 06:14:20
               date|                            |


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


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

* [Bug fortran/36112] Bounds-checking on character length not working for array-constructors
  2008-05-02 19:05 [Bug fortran/36112] New: Bounds-checking on character length not working for array-constructors d at domob dot eu
  2008-05-03  6:15 ` [Bug fortran/36112] " burnus at gcc dot gnu dot org
@ 2008-05-03 13:32 ` d at domob dot eu
  2008-05-03 13:35 ` d at domob dot eu
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: d at domob dot eu @ 2008-05-03 13:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from d at domob dot eu  2008-05-03 13:31 -------
Created an attachment (id=15568)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15568&action=view)
Four test cases for character-array constructors

This "patch" includes four test-cases that should all triger a bounds-checking
runtime error for character-array-constructors (including the one given in the
bug description); currently only one of them does this (also as written above).

I'm not sure about the correct dejagnu-format and the expected error messages,
but of course I'll adapt this during working on the patch if needed.  Are the
tests ok or do I misinterpret what the expected behaviour for them should be?

Do you think we need more tests?  Is there some thing despite character-arrays
that could/should trigger a bounds-checking error, like values with different
KIND parameters?  Do we need succeeding test cases, maybe in combination with
typespecs on array constructors (PR27997) when this is fixed?

Thanks for the comments!


-- 


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


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

* [Bug fortran/36112] Bounds-checking on character length not working for array-constructors
  2008-05-02 19:05 [Bug fortran/36112] New: Bounds-checking on character length not working for array-constructors d at domob dot eu
  2008-05-03  6:15 ` [Bug fortran/36112] " burnus at gcc dot gnu dot org
  2008-05-03 13:32 ` d at domob dot eu
@ 2008-05-03 13:35 ` d at domob dot eu
  2008-05-03 14:46 ` d at domob dot eu
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: d at domob dot eu @ 2008-05-03 13:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from d at domob dot eu  2008-05-03 13:35 -------
Just one more thought, for array-constructors with all constant
strings/components with length known at compile-time we should maybe give a
compiler error instead of a runtime-error?  Or only a warning and no
runtime-checking?

I believe at least for those arrays at the moment
gfc_resolve_char_array_constructor changes the string lengths so they all match
which means this is because there's no runtime error (IIRC).  If there should
be an error, we could do it there.


-- 


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


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

* [Bug fortran/36112] Bounds-checking on character length not working for array-constructors
  2008-05-02 19:05 [Bug fortran/36112] New: Bounds-checking on character length not working for array-constructors d at domob dot eu
                   ` (2 preceding siblings ...)
  2008-05-03 13:35 ` d at domob dot eu
@ 2008-05-03 14:46 ` d at domob dot eu
  2008-05-03 18:27 ` d at domob dot eu
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: d at domob dot eu @ 2008-05-03 14:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from d at domob dot eu  2008-05-03 14:45 -------
Created an attachment (id=15571)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15571&action=view)
More tests and first code

Four more test cases for different variations of character array constructors
and a first draft implementation of the bounds-checking for all-known-length
arrays; this however at the moment does not give a correct error message
(locus, is given twice).  I'm not familar with the error-reporting system yet,
so any hints/comments how to fix this (if a compile-time error is even what we
want here!).

Now I'll look into the problem with constructors as in the bug report, and then
we can put the patch in the right shape including the error message problem and
such.


-- 

d at domob dot eu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #15568|0                           |1
        is obsolete|                            |


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


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

* [Bug fortran/36112] Bounds-checking on character length not working for array-constructors
  2008-05-02 19:05 [Bug fortran/36112] New: Bounds-checking on character length not working for array-constructors d at domob dot eu
                   ` (3 preceding siblings ...)
  2008-05-03 14:46 ` d at domob dot eu
@ 2008-05-03 18:27 ` d at domob dot eu
  2008-05-04 11:24 ` d at domob dot eu
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: d at domob dot eu @ 2008-05-03 18:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from d at domob dot eu  2008-05-03 18:26 -------
Now I've been analysing a test looking like:

  test("abc", "foobar", "hello")
contains
  subroutine test(r, s)
    character(len=*) :: r, s
    character(len=128) :: arr(2)
    arr = (/ r, s /)
  end subroutine test
end

Which does not trigger the bounds-error, too.  It seems like the hidden
parameter _s (i.e. s's length) is used as the length of r for everything inside
the array constructor, that is for the bounds-checking runtime check (why it
does not trigger the error) and also for the memcpy call and related stuff.

So far I don't know why this is the case, but hopefully I'll find out later and
fix it...  Of course I'd appreciate any hints ;)


-- 


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


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

* [Bug fortran/36112] Bounds-checking on character length not working for array-constructors
  2008-05-02 19:05 [Bug fortran/36112] New: Bounds-checking on character length not working for array-constructors d at domob dot eu
                   ` (4 preceding siblings ...)
  2008-05-03 18:27 ` d at domob dot eu
@ 2008-05-04 11:24 ` d at domob dot eu
  2008-06-17 20:25 ` domob at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: d at domob dot eu @ 2008-05-04 11:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from d at domob dot eu  2008-05-04 11:23 -------
Now I believe I found out where the problem might be; as far as I can tell,
gfc_array_ctor_strlen in trans-array.c is the point where we determine the
length of the elements of a character array constructor; in the loop over all
elements, it seems that the output length is overwritten on each iteration,
thus returning the length of the last element, as I reported above.

I can't really tell how this value is used later and if this behaviour is
correct and the error comes later, but breaking the loop there after the first
iteration gives the correct result for the test-case I was looking at, so the
problem might really be there.

Any ideas/suggestions/comments on this?  And now I'll probably really wait...
:D


-- 


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


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

* [Bug fortran/36112] Bounds-checking on character length not working for array-constructors
  2008-05-02 19:05 [Bug fortran/36112] New: Bounds-checking on character length not working for array-constructors d at domob dot eu
                   ` (5 preceding siblings ...)
  2008-05-04 11:24 ` d at domob dot eu
@ 2008-06-17 20:25 ` domob at gcc dot gnu dot org
  2008-06-17 20:26 ` domob at gcc dot gnu dot org
  2008-06-18 13:56 ` domob at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: domob at gcc dot gnu dot org @ 2008-06-17 20:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from domob at gcc dot gnu dot org  2008-06-17 20:25 -------
Subject: Bug 36112

Author: domob
Date: Tue Jun 17 20:24:20 2008
New Revision: 136872

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=136872
Log:
2008-06-17  Daniel Kraft  <d@domob.eu>

        PR fortran/36112
        * array.c (gfc_resolve_character_array_constructor):  Check that all
        elements with constant character length have the same one rather than
        fixing it if no typespec is given, emit an error if they don't. 
Changed
        return type to "try" and return FAILURE for the case above.
        (gfc_resolve_array_constructor):  Removed unneeded call to
        gfc_resolve_character_array_constructor in this function.
        * gfortran.h (gfc_resolve_character_array_constructor):  Returns try.
        * trans-array.c (get_array_ctor_strlen):  Return length of first
element
        rather than last element.
        * resolve.c (gfc_resolve_expr):  Handle FAILURE return from
        gfc_resolve_character_array_constructor.

2008-06-17  Daniel Kraft  <d@domob.eu>

        PR fortran/36112
        * gfortran.dg/bounds_check_array_ctor_1.f90:  New test.
        * gfortran.dg/bounds_check_array_ctor_2.f90:  New test.
        * gfortran.dg/bounds_check_array_ctor_3.f90:  New test.
        * gfortran.dg/bounds_check_array_ctor_4.f90:  New test.
        * gfortran.dg/bounds_check_array_ctor_5.f90:  New test.
        * gfortran.dg/bounds_check_array_ctor_6.f90:  New test.
        * gfortran.dg/bounds_check_array_ctor_7.f90:  New test.
        * gfortran.dg/bounds_check_array_ctor_8.f90:  New test.
        * gfortran.dg/arrayio_0.f90:  Fixed invalid array constructor.
        * gfortran.dg/char_cons_len.f90:  Ditto.
        * gfortran.dg/char_initializer_actual.f90:  Ditto.
        * gfortran.dg/pr15959.f90:  Ditto.
        * gfortran.dg/transfer_simplify_2.f90:  Ditto.
        * gfortran.dg/char_length_1.f90:  Changed expected error messages.


Added:
    trunk/gcc/testsuite/gfortran.dg/bounds_check_array_ctor_1.f90
    trunk/gcc/testsuite/gfortran.dg/bounds_check_array_ctor_2.f90
    trunk/gcc/testsuite/gfortran.dg/bounds_check_array_ctor_3.f90
    trunk/gcc/testsuite/gfortran.dg/bounds_check_array_ctor_4.f90
    trunk/gcc/testsuite/gfortran.dg/bounds_check_array_ctor_5.f90
    trunk/gcc/testsuite/gfortran.dg/bounds_check_array_ctor_6.f90
    trunk/gcc/testsuite/gfortran.dg/bounds_check_array_ctor_7.f90
    trunk/gcc/testsuite/gfortran.dg/bounds_check_array_ctor_8.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/array.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/arrayio_0.f90
    trunk/gcc/testsuite/gfortran.dg/char_cons_len.f90
    trunk/gcc/testsuite/gfortran.dg/char_initialiser_actual.f90
    trunk/gcc/testsuite/gfortran.dg/char_length_1.f90
    trunk/gcc/testsuite/gfortran.dg/pr15959.f90
    trunk/gcc/testsuite/gfortran.dg/transfer_simplify_2.f90


-- 


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


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

* [Bug fortran/36112] Bounds-checking on character length not working for array-constructors
  2008-05-02 19:05 [Bug fortran/36112] New: Bounds-checking on character length not working for array-constructors d at domob dot eu
                   ` (6 preceding siblings ...)
  2008-06-17 20:25 ` domob at gcc dot gnu dot org
@ 2008-06-17 20:26 ` domob at gcc dot gnu dot org
  2008-06-18 13:56 ` domob at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: domob at gcc dot gnu dot org @ 2008-06-17 20:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from domob at gcc dot gnu dot org  2008-06-17 20:26 -------
Fixed.


-- 

domob at gcc dot gnu dot org changed:

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


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


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

* [Bug fortran/36112] Bounds-checking on character length not working for array-constructors
  2008-05-02 19:05 [Bug fortran/36112] New: Bounds-checking on character length not working for array-constructors d at domob dot eu
                   ` (7 preceding siblings ...)
  2008-06-17 20:26 ` domob at gcc dot gnu dot org
@ 2008-06-18 13:56 ` domob at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: domob at gcc dot gnu dot org @ 2008-06-18 13:56 UTC (permalink / raw)
  To: gcc-bugs



-- 

domob at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.4.0


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


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

end of thread, other threads:[~2008-06-18 13:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-02 19:05 [Bug fortran/36112] New: Bounds-checking on character length not working for array-constructors d at domob dot eu
2008-05-03  6:15 ` [Bug fortran/36112] " burnus at gcc dot gnu dot org
2008-05-03 13:32 ` d at domob dot eu
2008-05-03 13:35 ` d at domob dot eu
2008-05-03 14:46 ` d at domob dot eu
2008-05-03 18:27 ` d at domob dot eu
2008-05-04 11:24 ` d at domob dot eu
2008-06-17 20:25 ` domob at gcc dot gnu dot org
2008-06-17 20:26 ` domob at gcc dot gnu dot org
2008-06-18 13:56 ` domob 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).