This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Fortran,Patch] PR32669 Fix actual argument bound checking


:ADDPATCH fortran:

The actual argument bound checking had problems when the lower bound of an
array section was not specified and not one, which led to an
accepts-invalid/rejects-valid bug. Found by Janus.
The following patch has been build and check-gfortran tested on x86-64/Linux.

Ok for the trunk? (The bug was introduced with the enhanced formal/actual
argument checking five days ago [PR30940].)
Tobias

2007-07-08  Tobias Burnus  <burnus@net-b.de>

	PR fortran/32669
	* interface.c (get_expr_storage_size): Properly obtain lower bound.
	(compare_actual_formal): Add space before parenthesis.

2007-07-08  Tobias Burnus  <burnus@net-b.de>

	PR fortran/32669
	* gfortran.dg/argument_checking_6.f90: New.

Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c	(Revision 126457)
+++ gcc/fortran/interface.c	(Arbeitskopie)
@@ -1374,7 +1374,7 @@ get_expr_storage_size (gfc_expr *e)
 	  {
 	    long int start, end, stride;
 	    stride = 1;
-	    start = 1;
+
 	    if (ref->u.ar.stride[i])
 	      {
 		if (ref->u.ar.stride[i]->expr_type == EXPR_CONSTANT)
@@ -1390,6 +1390,11 @@ get_expr_storage_size (gfc_expr *e)
 		else
 		  return 0;
 	      }
+	    else if (ref->u.ar.as->lower[i]
+		     && ref->u.ar.as->lower[i]->expr_type == EXPR_CONSTANT)
+	      start = mpz_get_si (ref->u.ar.as->lower[i]->value.integer);
+	    else
+	      return 0;
 
 	    if (ref->u.ar.end[i])
 	      {
@@ -1595,8 +1600,8 @@ compare_actual_formal (gfc_actual_arglis
 	     }
 	 }
 
-      actual_size = get_expr_storage_size(a->expr);
-      formal_size = get_sym_storage_size(f->sym);
+      actual_size = get_expr_storage_size (a->expr);
+      formal_size = get_sym_storage_size (f->sym);
       if (actual_size != 0 && actual_size < formal_size)
 	{
 	  if (a->expr->ts.type == BT_CHARACTER && !f->sym->as && where)
Index: gcc/testsuite/gfortran.dg/argument_checking_6.f90
===================================================================
--- gcc/testsuite/gfortran.dg/argument_checking_6.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/argument_checking_6.f90	(Revision 0)
@@ -0,0 +1,24 @@
+! { dg-do compile }
+! PR fortran/32669
+!
+! Contributed by Janus Weil <jaydub66@gmail.com>
+!
+program tfe
+implicit none
+
+real,dimension(-1:1) ::  w
+real,dimension(1:4) ::  x
+real,dimension(0:3) ::  y
+real,dimension(-1:2) ::  z
+
+call sub(x(:))
+call sub(y(:))
+call sub(z(:))
+call sub(w(:)) ! { dg-error "too few elements" }
+
+contains
+  subroutine sub(a)
+    implicit none
+    real,dimension(1:4) :: a
+  end subroutine sub
+end program tfe

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]