]> gcc.gnu.org Git - gcc.git/commitdiff
re PR fortran/25071 (dummy argument larger than actual argument)
authorTobias Burnus <burnus@gcc.gnu.org>
Fri, 4 May 2007 07:54:06 +0000 (09:54 +0200)
committerTobias Burnus <burnus@gcc.gnu.org>
Fri, 4 May 2007 07:54:06 +0000 (09:54 +0200)
2007-05-04  Tobias Burnus  <burnus@net-b.de>

        PR fortran/25071
        * interface.c (compare_actual_formal): Check character length.

2007-05-04  Tobias Burnus  <burnus@net-b.de>

        PR fortran/25071
        * gfortran.dg/char_length_3.f90: New test.
        * gfortran.dg/char_result_2.f90: Fix test.

From-SVN: r124411

gcc/fortran/ChangeLog
gcc/fortran/interface.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/char_length_3.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/char_result_2.f90

index 66e61587fc095a2e4a46fa62cdccc6fd2798d44a..aa9fb997732bbc91f1fe6d69280faa99b0157873 100644 (file)
@@ -1,6 +1,11 @@
+2007-05-04  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/25071
+       * interface.c (compare_actual_formal): Check character length.
+
 2007-05-01  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
-        PR fortran/31732
+       PR fortran/31732
        * dependency.c (gfc_full_array_ref_p):  If the reference is
        to a single element, check that the array has a single
        element and that the correct element is referenced.
index 1672b1c3abc932d1e3ab9ce304066788864ce5c3..22a39b5246b4cf7282dbf5b803ce5cacfeb11e0d 100644 (file)
@@ -1369,6 +1369,34 @@ compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal,
          return 0;
        }
 
+       if (a->expr->ts.type == BT_CHARACTER
+          && a->expr->ts.cl && a->expr->ts.cl->length
+          && a->expr->ts.cl->length->expr_type == EXPR_CONSTANT
+          && f->sym->ts.cl && f->sym->ts.cl && f->sym->ts.cl->length
+          && f->sym->ts.cl->length->expr_type == EXPR_CONSTANT)
+        {
+          if (mpz_cmp (a->expr->ts.cl->length->value.integer,
+                       f->sym->ts.cl->length->value.integer) < 0)
+            {
+               if (where)
+                 gfc_error ("Character length of actual argument shorter "
+                            "than of dummy argument '%s' at %L",
+                            f->sym->name, &a->expr->where);
+               return 0;
+            }
+
+          if ((f->sym->attr.pointer || f->sym->attr.allocatable)
+              && (mpz_cmp (a->expr->ts.cl->length->value.integer,
+                          f->sym->ts.cl->length->value.integer) != 0))
+            {
+               if (where)
+                 gfc_error ("Character length mismatch between actual argument "
+                            "and pointer or allocatable dummy argument "
+                            "'%s' at %L", f->sym->name, &a->expr->where);
+               return 0;
+            }
+        }
+
       /* Satisfy 12.4.1.2 by ensuring that a procedure actual argument is
         provided for a procedure formal argument.  */
       if (a->expr->ts.type != BT_PROCEDURE
index 1f0e63713c5a77d7aa5ea417e19c6d031f29fd35..c55266ad9a135c68a067b0618eeb97db0fddeb8c 100644 (file)
@@ -1,3 +1,9 @@
+2007-05-04  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/25071
+       * gfortran.dg/char_length_3.f90: New test.
+       * gfortran.dg/char_result_2.f90: Fix test.
+
 2007-05-03  Zdenek Dvorak  <dvorakz@suse.cz>
 
        PR tree-optimization/30565
@@ -81,7 +87,7 @@
 
 2007-05-01  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
-        PR fortran/31732
+       PR fortran/31732
        * gfortran.dg/array_memset_2:  New test case.
 
 2007-05-01  Dorit Nuzman  <dorit@il.ibm.com>
diff --git a/gcc/testsuite/gfortran.dg/char_length_3.f90 b/gcc/testsuite/gfortran.dg/char_length_3.f90
new file mode 100644 (file)
index 0000000..cee55f6
--- /dev/null
@@ -0,0 +1,49 @@
+! { dg-do compile }
+! PR fortran/25071
+! Check if actual argument is too short
+!
+        program test
+           implicit none
+           character(len=10) :: v
+           character(len=10), target :: x
+           character(len=20), target :: y
+           character(len=30), target :: z
+           character(len=10), pointer :: ptr1
+           character(len=20), pointer :: ptr2
+           character(len=30), pointer :: ptr3
+           character(len=10), allocatable :: alloc1(:)
+           character(len=20), allocatable :: alloc2(:)
+           character(len=30), allocatable :: alloc3(:)
+           call foo(v) ! { dg-error "actual argument shorter than of dummy" }
+           call foo(x) ! { dg-error "actual argument shorter than of dummy" }
+           call foo(y)
+           call foo(z)
+           ptr1 => x
+           call foo(ptr1) ! { dg-error "actual argument shorter than of dummy" }
+           call bar(ptr1) ! { dg-error "actual argument shorter than of dummy" }
+           ptr2 => y
+           call foo(ptr2)
+           call bar(ptr2)
+           ptr3 => z
+           call foo(ptr3)
+           call bar(ptr3) ! { dg-error "Character length mismatch" }
+           allocate(alloc1(1))
+           allocate(alloc2(1))
+           allocate(alloc3(1))
+           call arr(alloc1) ! { dg-error "actual argument shorter than of dummy" }
+           call arr(alloc2)
+           call arr(alloc3) ! { dg-error "Character length mismatch" }
+        contains
+        subroutine foo(y)
+           character(len=20) :: y
+           y = 'hello world'
+        end subroutine
+        subroutine bar(y)
+           character(len=20),pointer :: y
+           y = 'hello world'
+        end subroutine
+        subroutine arr(y)
+           character(len=20),allocatable :: y(:)
+           y(1) = 'hello world'
+        end subroutine
+       end
index b7ecb6669c66762549be911254de425b914ffa1f..0df43aa06bca503bba62b0130d9c0b02dba1a415 100644 (file)
@@ -42,9 +42,11 @@ program main
   character (len = 80) :: text
   character (len = 70), target :: textt
   character (len = 70), pointer :: textp
+  character (len = 50), pointer :: textp2
 
   a = 42
   textp => textt
+  ! textp2 => textt(1:50) ! needs fixed PR31803
 
   call test (f1 (textp), 70)
   call test (f2 (textp, textp), 95)
@@ -53,7 +55,7 @@ program main
   call test (f5 (textp), 140)
   call test (f6 (textp), 29)
 
-  call indirect (textp)
+  ! call indirect (textp2) ! needs fixed PR31803
 contains
   function f3 (string)
     integer, parameter :: l1 = 30
@@ -93,7 +95,6 @@ contains
     call test (f1 (textp2), 50)
     call test (f2 (textp2, textp), 65)
     call test (f3 (textp2), 85)
-    call test (f4 (textp2), 192)
     call test (f5 (textp2), 100)
     call test (f6 (textp2), 9)
   end subroutine indirect
This page took 0.137777 seconds and 5 git commands to generate.