public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31243]  New: truncating strings longer than 2**32 characters
@ 2007-03-17 14:51 tkoenig at gcc dot gnu dot org
  2007-03-17 20:06 ` [Bug fortran/31243] " fxcoudert at gcc dot gnu dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-03-17 14:51 UTC (permalink / raw)
  To: gcc-bugs

The string lengths are truncated to 32-bit
values here, which shouldn't happen.

$ cat substr.f90
program main
  character (len=2_8**32_8+4_8) :: ch
  ch = ' '
  print *,ch(1:2_8**32_8+3_8)
end program main
$ gfortran -fdump-tree-original substr.f90
$ cat substr.f90.003t.original
MAIN__ ()
{
  char ch[1:4];

  _gfortran_set_std (68, 127, 0);
  __builtin_memmove (&ch, " ", 1);
  __builtin_memset (&ch + 1B, 32, 3);

...


-- 
           Summary: truncating strings longer than 2**32 characters
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org


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


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

* [Bug fortran/31243] truncating strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
@ 2007-03-17 20:06 ` fxcoudert at gcc dot gnu dot org
  2007-03-28 21:50 ` fxcoudert at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-17 20:06 UTC (permalink / raw)
  To: gcc-bugs



-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-03-17 20:06:45
               date|                            |


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


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

* [Bug fortran/31243] truncating strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
  2007-03-17 20:06 ` [Bug fortran/31243] " fxcoudert at gcc dot gnu dot org
@ 2007-03-28 21:50 ` fxcoudert at gcc dot gnu dot org
  2007-04-16 12:52 ` tobi at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-28 21:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fxcoudert at gcc dot gnu dot org  2007-03-28 22:50 -------
Same thing happens for local variables, character arguments and character
functions... Example of the first case:

subroutine foo(i)
  integer(kind=8), intent(in) :: i
  character(len=i) :: x

  print *, len(x)
end subroutine foo

program main
  character (len=2_8**32_8+4_8) :: ch
  ch = ' '
  print *,ch(1:2_8**32_8+3_8)
  print *, len(ch)
  call foo(2_8**32_8+4_8)
end program main


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |fxcoudert at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2007-03-17 20:06:45         |2007-03-28 22:50:08
               date|                            |


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


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

* [Bug fortran/31243] truncating strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
  2007-03-17 20:06 ` [Bug fortran/31243] " fxcoudert at gcc dot gnu dot org
  2007-03-28 21:50 ` fxcoudert at gcc dot gnu dot org
@ 2007-04-16 12:52 ` tobi at gcc dot gnu dot org
  2007-05-28 16:13 ` fxcoudert at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: tobi at gcc dot gnu dot org @ 2007-04-16 12:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from tobi at gcc dot gnu dot org  2007-04-16 13:52 -------
Issuing a warning would be a good thing, "INTEGER*8 value may be greater than
longest possible CHARACTER on your architecture", maybe even a runtime error in
the second case.  I hope you're not suggesting that we devise ways of
addressing 2**64 bytes on 32bit machines :-)


-- 

tobi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tobi at gcc dot gnu dot org


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


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

* [Bug fortran/31243] truncating strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2007-04-16 12:52 ` tobi at gcc dot gnu dot org
@ 2007-05-28 16:13 ` fxcoudert at gcc dot gnu dot org
  2007-12-25 23:32 ` tkoenig at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-05-28 16:13 UTC (permalink / raw)
  To: gcc-bugs



-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|fxcoudert at gcc dot gnu dot|unassigned at gcc dot gnu
                   |org                         |dot org
             Status|ASSIGNED                    |NEW


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


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

* [Bug fortran/31243] truncating strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2007-05-28 16:13 ` fxcoudert at gcc dot gnu dot org
@ 2007-12-25 23:32 ` tkoenig at gcc dot gnu dot org
  2008-07-24 16:32 ` domob at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-12-25 23:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from tkoenig at gcc dot gnu dot org  2007-12-25 23:32 -------
Maybe we could just issue a "compiler limit" error
message.


-- 


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


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

* [Bug fortran/31243] truncating strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2007-12-25 23:32 ` tkoenig at gcc dot gnu dot org
@ 2008-07-24 16:32 ` domob at gcc dot gnu dot org
  2009-01-27  5:00 ` jvdelisle at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: domob at gcc dot gnu dot org @ 2008-07-24 16:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from domob at gcc dot gnu dot org  2008-07-24 16:31 -------
This seems to be still in there...  Any interest that I work on this?  What's
about emitting a warning if either len= or a substring-reference expression is
of a KIND that can have larger values than the machine can handle?  As
suggested in comment #2 by Tobias S.

That is truely not too difficult.  For constant expressions, one could also try
to give an error whenever the value is too large.  Should I work on this or do
you think that's not important or even wanted?


-- 


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


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

* [Bug fortran/31243] truncating strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2008-07-24 16:32 ` domob at gcc dot gnu dot org
@ 2009-01-27  5:00 ` jvdelisle at gcc dot gnu dot org
  2009-04-17 22:13 ` jb at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2009-01-27  5:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jvdelisle at gcc dot gnu dot org  2009-01-27 05:00 -------
I am going to look at this for a bit.


-- 

jvdelisle at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jvdelisle at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2007-03-28 22:50:08         |2009-01-27 05:00:27
               date|                            |


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


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

* [Bug fortran/31243] truncating strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2009-01-27  5:00 ` jvdelisle at gcc dot gnu dot org
@ 2009-04-17 22:13 ` jb at gcc dot gnu dot org
  2009-04-17 22:42 ` dominiq at lps dot ens dot fr
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jb at gcc dot gnu dot org @ 2009-04-17 22:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jb at gcc dot gnu dot org  2009-04-17 22:13 -------
I'm not sure how this could be fixed in a "proper way" without breaking the
procedure call ABI. Gfortran follows pretty much every other Fortran compiler
in providing character length as a hidden argument of type default integer. 

In principle we could break this and make the length argument (s)size_t like
the string functions in C/C++ do, but that would probably be a major headache
for all those doing mixed C/Fortran programming the old fashioned way without
ISO_C_BINDING.

Of course, in principle one option could be to support larger strings as long
as no procedure calls are made, but that sounds pretty confusing and flaky
IMHO.

Considering that string sizes larger than 2**31 are pretty rare outside of
testcases, and IMHO not worth breaking the procedure call ABI for, the proper
resolution for this PR would be to just print out a "compiler limit" error
message like Thomas Koenig suggested.


-- 

jb at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jb at gcc dot gnu dot org


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


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

* [Bug fortran/31243] truncating strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2009-04-17 22:13 ` jb at gcc dot gnu dot org
@ 2009-04-17 22:42 ` dominiq at lps dot ens dot fr
  2009-04-18 22:07 ` jvdelisle at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: dominiq at lps dot ens dot fr @ 2009-04-17 22:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from dominiq at lps dot ens dot fr  2009-04-17 22:42 -------
Compiling the code in comment #1 gives:

[ibook-dhum] f90/bug% gfc42 pr31243.f90
pr31243.f90:12.15:

  print *, len(ch)
              1
Error: Result of LEN overflows its kind at (1)

It compiles with -fdefault-integer-8 and gives


           4294967300
                    4

when executed. Note that "print *,ch(1:2_8**32_8+3_8)" prints three spaces and
the value of 'i' in the subroutine is 4294967300.


-- 


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


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

* [Bug fortran/31243] truncating strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2009-04-17 22:42 ` dominiq at lps dot ens dot fr
@ 2009-04-18 22:07 ` jvdelisle at gcc dot gnu dot org
  2009-05-16 16:15 ` fxcoudert at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2009-04-18 22:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jvdelisle at gcc dot gnu dot org  2009-04-18 22:07 -------
Unassigning myself, time constraints


-- 

jvdelisle at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|jvdelisle at gcc dot gnu dot|unassigned at gcc dot gnu
                   |org                         |dot org
             Status|ASSIGNED                    |NEW


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


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

* [Bug fortran/31243] truncating strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2009-04-18 22:07 ` jvdelisle at gcc dot gnu dot org
@ 2009-05-16 16:15 ` fxcoudert at gcc dot gnu dot org
  2009-05-16 16:53 ` fxcoudert at gcc dot gnu dot org
  2009-05-16 17:01 ` [Bug fortran/31243] Detect " fxcoudert at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2009-05-16 16:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from fxcoudert at gcc dot gnu dot org  2009-05-16 16:15 -------
Patch posted for the compile-time part of this PR:
http://gcc.gnu.org/ml/gcc-patches/2009-05/msg01013.html

Here are three testcases that should be handled when runtime checking is
performed:

$ cat a3.f90 
program main
  implicit none
  character(len=10) :: s
  integer(kind=8) :: i

  s = 'xxxxxxxxxx'
  i = 2_8**32_8+3_8
  print *, s(1:i) ! runtime error expected
  print *, s(i:i) ! runtime error expected

end program main

$ cat a4.f90 
program main

  call foo(2_8**32_8+4_8)

contains

  subroutine foo(i)
    integer(kind=8), intent(in) :: i
    character(len=i) :: x

    print *, len(x)
  end subroutine foo

end program main

$ cat a5.f90 
program main

  print *, foo(2_8**32_8+4_8)

contains

  function foo(i)
    integer(kind=8), intent(in) :: i
    character(len=i) :: foo

    foo = "x"
  end function foo

end program main


-- 


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


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

* [Bug fortran/31243] truncating strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
                   ` (10 preceding siblings ...)
  2009-05-16 16:15 ` fxcoudert at gcc dot gnu dot org
@ 2009-05-16 16:53 ` fxcoudert at gcc dot gnu dot org
  2009-05-16 17:01 ` [Bug fortran/31243] Detect " fxcoudert at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2009-05-16 16:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from fxcoudert at gcc dot gnu dot org  2009-05-16 16:53 -------
Subject: Bug 31243

Author: fxcoudert
Date: Sat May 16 16:53:02 2009
New Revision: 147619

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147619
Log:
        PR fortran/31243

        * resolve.c (resolve_substring): Don't allow too large substring
        indexes.
        (gfc_resolve_substring_charlen): Fix typo.
        (gfc_resolve_character_operator): Fix typo.
        (resolve_charlen): Catch unreasonably large string lengths.
        * simplify.c (gfc_simplify_len): Don't error out on LEN
        range checks.

        * gcc/testsuite/gfortran.dg/string_1.f90: New test.
        * gcc/testsuite/gfortran.dg/string_2.f90: New test.
        * gcc/testsuite/gfortran.dg/string_3.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/string_1.f90
    trunk/gcc/testsuite/gfortran.dg/string_2.f90
    trunk/gcc/testsuite/gfortran.dg/string_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/31243] Detect strings longer than 2**32 characters
  2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
                   ` (11 preceding siblings ...)
  2009-05-16 16:53 ` fxcoudert at gcc dot gnu dot org
@ 2009-05-16 17:01 ` fxcoudert at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2009-05-16 17:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from fxcoudert at gcc dot gnu dot org  2009-05-16 17:00 -------
Now, these very long strings are caught at compile-time when possible. We
should also add runtime checks, for non-constant lengths; three such examples
are given in comment #9.

Removing the "wrong-code" keyword: it's just an issue of diagnostics. String
length are type parameters, and they have a kind that is processor-dependent,
so it's OK to have an upper limit.


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxcoudert at gcc dot gnu dot
                   |                            |org
           Keywords|wrong-code                  |diagnostic
   Last reconfirmed|2009-01-27 05:00:27         |2009-05-16 17:00:40
               date|                            |
            Summary|truncating strings longer   |Detect strings longer than
                   |than 2**32 characters       |2**32 characters
            Version|4.3.0                       |4.5.0


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


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

end of thread, other threads:[~2009-05-16 17:01 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-17 14:51 [Bug fortran/31243] New: truncating strings longer than 2**32 characters tkoenig at gcc dot gnu dot org
2007-03-17 20:06 ` [Bug fortran/31243] " fxcoudert at gcc dot gnu dot org
2007-03-28 21:50 ` fxcoudert at gcc dot gnu dot org
2007-04-16 12:52 ` tobi at gcc dot gnu dot org
2007-05-28 16:13 ` fxcoudert at gcc dot gnu dot org
2007-12-25 23:32 ` tkoenig at gcc dot gnu dot org
2008-07-24 16:32 ` domob at gcc dot gnu dot org
2009-01-27  5:00 ` jvdelisle at gcc dot gnu dot org
2009-04-17 22:13 ` jb at gcc dot gnu dot org
2009-04-17 22:42 ` dominiq at lps dot ens dot fr
2009-04-18 22:07 ` jvdelisle at gcc dot gnu dot org
2009-05-16 16:15 ` fxcoudert at gcc dot gnu dot org
2009-05-16 16:53 ` fxcoudert at gcc dot gnu dot org
2009-05-16 17:01 ` [Bug fortran/31243] Detect " fxcoudert 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).