public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/40383]  New: [4.5 Regression] incorrect bounds checking with optional character arguments
@ 2009-06-09  7:41 jv244 at cam dot ac dot uk
  2009-06-09  7:44 ` [Bug fortran/40383] " jv244 at cam dot ac dot uk
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jv244 at cam dot ac dot uk @ 2009-06-09  7:41 UTC (permalink / raw)
  To: gcc-bugs

trunk has been broken with CP2K since some time, which I believed to be a side
effect of PR40332, but the following is a stand-alone reduced testcase:

vondele@pcihopt3:/data03/vondele/bug> gfortran -fbounds-check -g test.f90
vondele@pcihopt3:/data03/vondele/bug> ./a.out
At line 8 of file test.f90
Fortran runtime error: Actual string length is shorter than the declared one
for dummy argument 'a' (0/80)
vondele@pcihopt3:/data03/vondele/bug> cat test.f90
MODULE M1
  INTEGER, PARAMETER :: default_string_length=80
END MODULE M1
MODULE M2
 USE M1
 IMPLICIT NONE
CONTAINS
 FUNCTION F1(a,b,c,d) RESULT(RES)
   CHARACTER(LEN=default_string_length), OPTIONAL :: a,b,c,d
   LOGICAL :: res
 END FUNCTION F1
END MODULE M2

MODULE M3
 USE M1
 USE M2
 IMPLICIT NONE
CONTAINS
 SUBROUTINE S1
   CHARACTER(LEN=default_string_length) :: a,b
   LOGICAL :: L1
   INTEGER :: i
   DO I=1,10
      L1=F1(a,b)
   ENDDO
 END SUBROUTINE
END MODULE M3

USE M3
CALL S1
END

this is likely related to the optional arguments.


-- 
           Summary: [4.5 Regression] incorrect bounds checking with optional
                    character arguments
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jv244 at cam dot ac dot uk


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


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

* [Bug fortran/40383] [4.5 Regression] incorrect bounds checking with optional character arguments
  2009-06-09  7:41 [Bug fortran/40383] New: [4.5 Regression] incorrect bounds checking with optional character arguments jv244 at cam dot ac dot uk
@ 2009-06-09  7:44 ` jv244 at cam dot ac dot uk
  2009-06-09 10:02 ` burnus at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jv244 at cam dot ac dot uk @ 2009-06-09  7:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from jv244 at cam dot ac dot uk  2009-06-09 07:44 -------
I'm guessing due to :

2009-04-11  Daniel Kraft  <d@domob.eu>

        PR fortran/37746


-- 

jv244 at cam dot ac dot uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |d at domob dot eu


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


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

* [Bug fortran/40383] [4.5 Regression] incorrect bounds checking with optional character arguments
  2009-06-09  7:41 [Bug fortran/40383] New: [4.5 Regression] incorrect bounds checking with optional character arguments jv244 at cam dot ac dot uk
  2009-06-09  7:44 ` [Bug fortran/40383] " jv244 at cam dot ac dot uk
@ 2009-06-09 10:02 ` burnus at gcc dot gnu dot org
  2009-06-09 10:30 ` burnus at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-09 10:02 UTC (permalink / raw)
  To: gcc-bugs



-- 

burnus 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         |2009-06-09 10:02:18
               date|                            |
   Target Milestone|---                         |4.5.0


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


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

* [Bug fortran/40383] [4.5 Regression] incorrect bounds checking with optional character arguments
  2009-06-09  7:41 [Bug fortran/40383] New: [4.5 Regression] incorrect bounds checking with optional character arguments jv244 at cam dot ac dot uk
  2009-06-09  7:44 ` [Bug fortran/40383] " jv244 at cam dot ac dot uk
  2009-06-09 10:02 ` burnus at gcc dot gnu dot org
@ 2009-06-09 10:30 ` burnus at gcc dot gnu dot org
  2009-06-09 12:09 ` burnus at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-09 10:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from burnus at gcc dot gnu dot org  2009-06-09 10:29 -------
I think the patch for PR fortran/37746 is OK, but something else goes wrong:

f1 (character(kind=1)[1:80] * a, character(kind=1)[1:80] * b,
character(kind=1)[1:80] * c, character(kind=1)[1:80] * d, integer(kind=4) _a,
integer(kin
d=4) _b, integer(kind=4) _c, integer(kind=4) _d)

if ((logical(kind=4)) __builtin_expect ((integer(kind=8))
                                        (_d <= 79 && (_d != 0 || a != 0B)), 0))


The the check itself is OK, but it should be _a and not _d:
                                        (_a <= 79 && (_a != 0 || a != 0B))


For some reason the length of the last string is always used. The source looks
OK:

        fsym = formal->sym;
        cl = fsym->ts.cl;
        cond = fold_build2 (comparison, boolean_type_node,
                            cl->passed_length, cl->backend_decl);

Thus somehow cl->backend_decl is wrong. That is probably a side effect of all
having the same length.


-- 

burnus 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=40383


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

* [Bug fortran/40383] [4.5 Regression] incorrect bounds checking with optional character arguments
  2009-06-09  7:41 [Bug fortran/40383] New: [4.5 Regression] incorrect bounds checking with optional character arguments jv244 at cam dot ac dot uk
                   ` (2 preceding siblings ...)
  2009-06-09 10:30 ` burnus at gcc dot gnu dot org
@ 2009-06-09 12:09 ` burnus at gcc dot gnu dot org
  2009-06-10 12:02 ` burnus at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-09 12:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from burnus at gcc dot gnu dot org  2009-06-09 12:09 -------
The problem is that fsym->ts.cl of all of "a", "b", "c" and "d" to the same
struct:

(gdb) p sym->formal->sym->name
$17 = 0x2aaaaab31ec8 "a"
(gdb) p sym->formal->sym->ts
$18 = {... cl = 0x12b6da0 ...}
(gdb) p sym->formal->next->sym->name
$19 = 0x2aaaaab31ed0 "b"
(gdb) p sym->formal->next->sym->ts
$20 = {... cl = 0x12b6da0 ...}

Thus  f->sym->ts.cl->passed_length = length;  in create_function_arglist does
not do what one expects.


-- 


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


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

* [Bug fortran/40383] [4.5 Regression] incorrect bounds checking with optional character arguments
  2009-06-09  7:41 [Bug fortran/40383] New: [4.5 Regression] incorrect bounds checking with optional character arguments jv244 at cam dot ac dot uk
                   ` (3 preceding siblings ...)
  2009-06-09 12:09 ` burnus at gcc dot gnu dot org
@ 2009-06-10 12:02 ` burnus at gcc dot gnu dot org
  2009-06-10 12:05 ` burnus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-10 12:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from burnus at gcc dot gnu dot org  2009-06-10 12:02 -------
Patch -- I believe it does the right thing; especially, it preserves
backend_decl. If one copied the type earlier, the backend_decl would be
different and the backend does not like it, when the same type has different
declarations. (It still happens independent of this patch, but it makes sense
not to make the problem worse; cf. PR 38913. The "->next" should also be
correct, I think.

--- trans-decl.c        (revision 148340)
+++ trans-decl.c        (working copy)
@@ -1694,6 +1694,22 @@ create_function_arglist (gfc_symbol * sy
          gfc_finish_decl (length);

          /* Remember the passed value.  */
+          if (f->sym->ts.cl->passed_length != NULL)
+            {
+             /* This can happen if the same type is used for multiple
+                arguments. We need to copy cl as otherwise
+                cl->passed_length gets overwritten.  */
+             gfc_charlen *cl, *cl2;
+             cl = f->sym->ts.cl;
+             f->sym->ts.cl = gfc_get_charlen();
+             f->sym->ts.cl->length = cl->length;
+             f->sym->ts.cl->backend_decl = cl->backend_decl;
+             f->sym->ts.cl->length_from_typespec = cl->length_from_typespec;
+             f->sym->ts.cl->resolved = cl->resolved;
+             cl2 = f->sym->ts.cl->next;
+             f->sym->ts.cl->next = cl;
+              cl->next = cl2;
+            }
          f->sym->ts.cl->passed_length = length;

          /* Use the passed value for assumed length variables.  */


-- 


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


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

* [Bug fortran/40383] [4.5 Regression] incorrect bounds checking with optional character arguments
  2009-06-09  7:41 [Bug fortran/40383] New: [4.5 Regression] incorrect bounds checking with optional character arguments jv244 at cam dot ac dot uk
                   ` (4 preceding siblings ...)
  2009-06-10 12:02 ` burnus at gcc dot gnu dot org
@ 2009-06-10 12:05 ` burnus at gcc dot gnu dot org
  2009-06-16  6:57 ` burnus at gcc dot gnu dot org
  2009-06-16  6:58 ` burnus at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-10 12:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from burnus at gcc dot gnu dot org  2009-06-10 12:05 -------
Forgot to mention: I will not be able to regtest/submit the patch before Monday
evening.


-- 


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


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

* [Bug fortran/40383] [4.5 Regression] incorrect bounds checking with optional character arguments
  2009-06-09  7:41 [Bug fortran/40383] New: [4.5 Regression] incorrect bounds checking with optional character arguments jv244 at cam dot ac dot uk
                   ` (5 preceding siblings ...)
  2009-06-10 12:05 ` burnus at gcc dot gnu dot org
@ 2009-06-16  6:57 ` burnus at gcc dot gnu dot org
  2009-06-16  6:58 ` burnus at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-16  6:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from burnus at gcc dot gnu dot org  2009-06-16 06:57 -------
Subject: Bug 40383

Author: burnus
Date: Tue Jun 16 06:57:09 2009
New Revision: 148517

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148517
Log:
2009-06-16  Tobias Burnus  <burnus@net-b.de>

        PR fortran/40383
        * trans-decl.c (create_function_arglist): Copy formal charlist
        * to
        have a proper passed_length for -fcheck=bounds.

2009-06-16  Tobias Burnus  <burnus@net-b.de>

        PR fortran/40383
        * gfortran.dg/bounds_check_strlen_8.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/bounds_check_strlen_8.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/40383] [4.5 Regression] incorrect bounds checking with optional character arguments
  2009-06-09  7:41 [Bug fortran/40383] New: [4.5 Regression] incorrect bounds checking with optional character arguments jv244 at cam dot ac dot uk
                   ` (6 preceding siblings ...)
  2009-06-16  6:57 ` burnus at gcc dot gnu dot org
@ 2009-06-16  6:58 ` burnus at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-16  6:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from burnus at gcc dot gnu dot org  2009-06-16 06:57 -------
FIXED on the trunk (4.5).
Patch was: http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01147.html

See also follow-up PR 40452.


-- 

burnus at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2009-06-16  6:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-09  7:41 [Bug fortran/40383] New: [4.5 Regression] incorrect bounds checking with optional character arguments jv244 at cam dot ac dot uk
2009-06-09  7:44 ` [Bug fortran/40383] " jv244 at cam dot ac dot uk
2009-06-09 10:02 ` burnus at gcc dot gnu dot org
2009-06-09 10:30 ` burnus at gcc dot gnu dot org
2009-06-09 12:09 ` burnus at gcc dot gnu dot org
2009-06-10 12:02 ` burnus at gcc dot gnu dot org
2009-06-10 12:05 ` burnus at gcc dot gnu dot org
2009-06-16  6:57 ` burnus at gcc dot gnu dot org
2009-06-16  6:58 ` burnus 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).