re PR fortran/40452 (-fbounds-check: False positive due to ignoring storage association)
authorTobias Burnus <burnus@net-b.de>
Sat, 20 Jun 2009 18:07:10 +0000 (20:07 +0200)
committerTobias Burnus <burnus@gcc.gnu.org>
Sat, 20 Jun 2009 18:07:10 +0000 (20:07 +0200)
2009-06-20  Tobias Burnus  <burnus@net-b.de>

        PR fortran/40452
        * trans-decl.c (add_argument_checking): Disable bounds check
        for allowed argument storage association.

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

        PR fortran/40452
        * gfortran.dg/bounds_check_strlen_9.f90: New test.

From-SVN: r148750

gcc/fortran/ChangeLog
gcc/fortran/trans-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/bounds_check_strlen_9.f90 [new file with mode: 0644]

index c38b91a..0d88c4b 100644 (file)
@@ -1,3 +1,9 @@
+2009-06-20  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/40452
+       * trans-decl.c (add_argument_checking): Disable bounds check
+       for allowed argument storage association.
+
 2009-06-19  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/40440
index 5af00a9..091d394 100644 (file)
@@ -3835,7 +3835,11 @@ add_argument_checking (stmtblock_t *block, gfc_symbol *sym)
 
        /* For POINTER, ALLOCATABLE and assumed-shape dummy arguments, the
           string lengths must match exactly.  Otherwise, it is only required
-          that the actual string length is *at least* the expected one.  */
+          that the actual string length is *at least* the expected one.
+          Sequence association allows for a mismatch of the string length
+          if the actual argument is (part of) an array, but only if the
+          dummy argument is an array. (See "Sequence association" in
+          Section 12.4.1.4 for F95 and 12.4.1.5 for F2003.)  */
        if (fsym->attr.pointer || fsym->attr.allocatable
            || (fsym->as && fsym->as->type == AS_ASSUMED_SHAPE))
          {
@@ -3843,6 +3847,8 @@ add_argument_checking (stmtblock_t *block, gfc_symbol *sym)
            message = _("Actual string length does not match the declared one"
                        " for dummy argument '%s' (%ld/%ld)");
          }
+       else if (fsym->as && fsym->as->rank != 0)
+         continue;
        else
          {
            comparison = LT_EXPR;
index dcc2e53..210d211 100644 (file)
@@ -1,3 +1,8 @@
+2009-06-20  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/40452
+       * gfortran.dg/bounds_check_strlen_9.f90: New test.
+
 2009-06-19  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/40440
diff --git a/gcc/testsuite/gfortran.dg/bounds_check_strlen_9.f90 b/gcc/testsuite/gfortran.dg/bounds_check_strlen_9.f90
new file mode 100644 (file)
index 0000000..89622e2
--- /dev/null
@@ -0,0 +1,20 @@
+! { dg-do run }
+! { dg-options "-fbounds-check" }
+!
+! PR fortran/40452
+! The following program is valid Fortran 90 and later.
+! The storage-sequence association of the dummy argument
+! allows that the actual argument ["ab", "cd"] is mapped
+! to the dummy argument a(1) which perfectly fits.
+! (The dummy needs to be an array, however.)
+!
+
+program test
+  implicit none
+  call sub(["ab", "cd"])
+contains
+  subroutine sub(a)
+   character(len=4) :: a(1)
+   print *, a(1)
+  end subroutine sub
+end program test