public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter
@ 2008-10-06 11:33 kloedej at knmi dot nl
2008-10-06 14:48 ` [Bug fortran/37746] " kargl at gcc dot gnu dot org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: kloedej at knmi dot nl @ 2008-10-06 11:33 UTC (permalink / raw)
To: gcc-bugs
The following testcase of (I think) valid Fortran90 code, shows a strange
error. It copies all characters of a text string except for the first
character, which for some unknown reason is replaced by a space.
The essential element seems to be the use of the expression len(a)+1 to
dimension the size of string b.
subroutine copy(a,b)
character(len=*), intent(in) :: a
character(len=len(a)+1), intent(out) :: b
integer :: c
print *,"inside1: a = ["//trim(a)//"]"
b(:)=' '
c=len_trim(a)
b(1:c)=a(1:c)
print *,"inside2: a = ["//trim(a)//"]"
print *,"len_trim(a)=",c
print *,"inside: b = ["//trim(b)//"]"
end subroutine copy
program Test_StrCopy
character(len=50) :: a,b
a = "abcdefg"
call copy(a,b)
end program Test_StrCopy
After compiling with: gfortran -o Test_Copy Test_Copy.F90
I get this result:
>Test_Copy
inside1: a = [abcdefg]
inside2: a = [ bcdefg]
len_trim(a)= 7
inside: b = [ bcdefg]
>
Clearly, the problem seems to be that the intent(in) variable a gets modified,
which should never happen.
gfortran version used for testing was:
gfortran -v
Using built-in specs.
Target: i586-pc-linux-gnu
Configured with: /home/fx/gfortran_nightbuild/trunk/configure
--prefix=/home/fx/gfortran_nightbuild/irun-20081005
--enable-languages=c,fortran --build=i586-pc-linux-gnu
--enable-checking=release --with-gmp=/home/fx/gfortran_nightbuild/software
Thread model: posix
gcc version 4.4.0 20081005 (experimental) [trunk revision 140878] (GCC)
>
Best regards,
Jos de Kloe, KNMI
--
Summary: string copy fails, due to changed intent(in) parameter
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kloedej at knmi dot nl
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37746
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/37746] string copy fails, due to changed intent(in) parameter
2008-10-06 11:33 [Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter kloedej at knmi dot nl
@ 2008-10-06 14:48 ` kargl at gcc dot gnu dot org
2008-10-06 19:54 ` burnus at gcc dot gnu dot org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: kargl at gcc dot gnu dot org @ 2008-10-06 14:48 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from kargl at gcc dot gnu dot org 2008-10-06 14:47 -------
Your code works if you fix the bug. You have two choices
program Test_StrCopy
character(len=50) :: a
character(len=51) :: b
a = "abcdefg"
call copy(a,b)
end program Test_StrCopy
or
subroutine copy(a,b)
character(len=*), intent(in) :: a
character(len=len(a)), intent(out) :: b
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37746
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/37746] string copy fails, due to changed intent(in) parameter
2008-10-06 11:33 [Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter kloedej at knmi dot nl
2008-10-06 14:48 ` [Bug fortran/37746] " kargl at gcc dot gnu dot org
@ 2008-10-06 19:54 ` burnus at gcc dot gnu dot org
2008-10-07 11:25 ` kloedej at knmi dot nl
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-10-06 19:54 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from burnus at gcc dot gnu dot org 2008-10-06 19:53 -------
I think the true bug is that -fbounds-check misses the problem. NAG f95 prints
at run time:
CHARACTER actual arg LEN=50 shorter than dummy arg LEN=51
Program terminated by fatal error
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37746
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/37746] string copy fails, due to changed intent(in) parameter
2008-10-06 11:33 [Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter kloedej at knmi dot nl
2008-10-06 14:48 ` [Bug fortran/37746] " kargl at gcc dot gnu dot org
2008-10-06 19:54 ` burnus at gcc dot gnu dot org
@ 2008-10-07 11:25 ` kloedej at knmi dot nl
2008-10-12 11:35 ` [Bug fortran/37746] bounds check of string dummy arguments tkoenig at gcc dot gnu dot org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: kloedej at knmi dot nl @ 2008-10-07 11:25 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from kloedej at knmi dot nl 2008-10-07 11:23 -------
Hi,
thanks for this discussion.
I do agree now that this code was invalid. I was thinking otherwise because no
compiletime or runtime error was issued by any of the compilers that I tried.
Checking this during compilation should at least be possible when the interface
of the subroutine is known, so when it is defined inside a module, but gfortran
also accepts that case without complaining.
best regards,
Jos de Kloe.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37746
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/37746] bounds check of string dummy arguments
2008-10-06 11:33 [Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter kloedej at knmi dot nl
` (2 preceding siblings ...)
2008-10-07 11:25 ` kloedej at knmi dot nl
@ 2008-10-12 11:35 ` tkoenig at gcc dot gnu dot org
2008-12-20 19:11 ` domob at gcc dot gnu dot org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-10-12 11:35 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from tkoenig at gcc dot gnu dot org 2008-10-12 11:33 -------
Confirm, updated subject, blocks bounds-checking meta-bug.
--
tkoenig at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
OtherBugsDependingO| |27766
nThis| |
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2008-10-12 11:33:42
date| |
Summary|string copy fails, due to |bounds check of string dummy
|changed intent(in) parameter|arguments
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37746
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/37746] bounds check of string dummy arguments
2008-10-06 11:33 [Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter kloedej at knmi dot nl
` (3 preceding siblings ...)
2008-10-12 11:35 ` [Bug fortran/37746] bounds check of string dummy arguments tkoenig at gcc dot gnu dot org
@ 2008-12-20 19:11 ` domob at gcc dot gnu dot org
2009-01-04 8:41 ` domob at gcc dot gnu dot org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: domob at gcc dot gnu dot org @ 2008-12-20 19:11 UTC (permalink / raw)
To: gcc-bugs
--
domob at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |domob at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2008-10-12 11:33:42 |2008-12-20 19:08:02
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37746
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/37746] bounds check of string dummy arguments
2008-10-06 11:33 [Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter kloedej at knmi dot nl
` (4 preceding siblings ...)
2008-12-20 19:11 ` domob at gcc dot gnu dot org
@ 2009-01-04 8:41 ` domob at gcc dot gnu dot org
2009-01-04 8:42 ` domob at gcc dot gnu dot org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: domob at gcc dot gnu dot org @ 2009-01-04 8:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from domob at gcc dot gnu dot org 2009-01-04 08:40 -------
*** Bug 35943 has been marked as a duplicate of this bug. ***
--
domob at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |burnus at gcc dot gnu dot
| |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37746
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/37746] bounds check of string dummy arguments
2008-10-06 11:33 [Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter kloedej at knmi dot nl
` (5 preceding siblings ...)
2009-01-04 8:41 ` domob at gcc dot gnu dot org
@ 2009-01-04 8:42 ` domob at gcc dot gnu dot org
2009-04-11 16:45 ` domob at gcc dot gnu dot org
2009-04-11 16:47 ` domob at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: domob at gcc dot gnu dot org @ 2009-01-04 8:42 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from domob at gcc dot gnu dot org 2009-01-04 08:41 -------
Here's a patch: http://gcc.gnu.org/ml/fortran/2008-12/msg00273.html
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37746
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/37746] bounds check of string dummy arguments
2008-10-06 11:33 [Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter kloedej at knmi dot nl
` (6 preceding siblings ...)
2009-01-04 8:42 ` domob at gcc dot gnu dot org
@ 2009-04-11 16:45 ` domob at gcc dot gnu dot org
2009-04-11 16:47 ` domob at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: domob at gcc dot gnu dot org @ 2009-04-11 16:45 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from domob at gcc dot gnu dot org 2009-04-11 16:44 -------
Subject: Bug 37746
Author: domob
Date: Sat Apr 11 16:44:37 2009
New Revision: 145958
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145958
Log:
2009-04-11 Daniel Kraft <d@domob.eu>
PR fortran/37746
* gfortran.h (struct gfc_charlen): New field `passed_length' to store
the actual passed string length for dummy arguments.
* trans-decl.c (gfc_create_string_length): Formatting fixes and added
assertion, moved a local variable into the innermost block it is
needed.
(create_function_arglist): Removed TODO about the check being
implemented and initialize cl->passed_length here.
(add_argument_checking): New method.
(gfc_generate_function_code): Call the argument checking method.
2009-04-11 Daniel Kraft <d@domob.eu>
PR fortran/37746
* gfortran.dg/bounds_check_strlen_1.f90: New test.
* gfortran.dg/bounds_check_strlen_2.f90: New test.
* gfortran.dg/bounds_check_strlen_3.f90: New test.
* gfortran.dg/bounds_check_strlen_4.f90: New test.
* gfortran.dg/bounds_check_strlen_5.f90: New test.
* gfortran.dg/bounds_check_strlen_6.f90: New test.
* gfortran.dg/bounds_check_strlen_7.f90: New test.
* gfortran.fortran-torture/execute/intrinsic_index.f90: Fix wrong
expected string length that failed with -fbounds-check now.
* gfortran.fortran-torture/execute/intrinsic_trim.f90: Ditto.
Added:
trunk/gcc/testsuite/gfortran.dg/bounds_check_strlen_1.f90
trunk/gcc/testsuite/gfortran.dg/bounds_check_strlen_2.f90
trunk/gcc/testsuite/gfortran.dg/bounds_check_strlen_3.f90
trunk/gcc/testsuite/gfortran.dg/bounds_check_strlen_4.f90
trunk/gcc/testsuite/gfortran.dg/bounds_check_strlen_5.f90
trunk/gcc/testsuite/gfortran.dg/bounds_check_strlen_6.f90
trunk/gcc/testsuite/gfortran.dg/bounds_check_strlen_7.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/gfortran.h
trunk/gcc/fortran/trans-decl.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_index.f90
trunk/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_trim.f90
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37746
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/37746] bounds check of string dummy arguments
2008-10-06 11:33 [Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter kloedej at knmi dot nl
` (7 preceding siblings ...)
2009-04-11 16:45 ` domob at gcc dot gnu dot org
@ 2009-04-11 16:47 ` domob at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: domob at gcc dot gnu dot org @ 2009-04-11 16:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from domob at gcc dot gnu dot org 2009-04-11 16:46 -------
Fixed on trunk.
--
domob at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37746
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2009-04-11 16:47 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-06 11:33 [Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter kloedej at knmi dot nl
2008-10-06 14:48 ` [Bug fortran/37746] " kargl at gcc dot gnu dot org
2008-10-06 19:54 ` burnus at gcc dot gnu dot org
2008-10-07 11:25 ` kloedej at knmi dot nl
2008-10-12 11:35 ` [Bug fortran/37746] bounds check of string dummy arguments tkoenig at gcc dot gnu dot org
2008-12-20 19:11 ` domob at gcc dot gnu dot org
2009-01-04 8:41 ` domob at gcc dot gnu dot org
2009-01-04 8:42 ` domob at gcc dot gnu dot org
2009-04-11 16:45 ` domob at gcc dot gnu dot org
2009-04-11 16:47 ` 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).