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]

[patch, fortran] [4.2/4.3 Regression] PR32002, insufficient conformance check


Currently, gfortran does not flag an error on code like this:

    real :: a(3), b(2) = 0.0
    a = COS(b)
    end

In primary.c (match_actual_arg) expressions of actuals arguements are set to 
BT_PROCEDURE on default, to be changed later. In this case, this is done in 
resolve.c (resolve_actual_arglist), but then the changed expression is not 
resolved correctly. Hence, attached patch simply adds a call to 
gfc_resolve_expr() when a variable was identified. 

FX, Paul could either of you double check this approach? Both of you worked on 
PR27900, this might be an aftermath thereof?!


:ADDPATCH fortran:

gcc/fortran:
2005-05-20  Jerry DeLisle  <jvdelisle@verizon.net>
            Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/32002
	* resolve.c (resolve_actual_arglist): Resolve actual argument after 
	being identified as variable.


gcc/testsuite:
2005-05-20  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/32002
	* gfortran.dg/pr32002.f90: New test.
	

Regression tested on ?-?-? by Jerry and on i686-pc-linux-gnu by myself. 
Ok for 4.2 and trunk?

Regards
	Daniel

Index: resolve.c
===================================================================
--- resolve.c	(revision 124790)
+++ resolve.c	(working copy)
@@ -1013,6 +1013,13 @@
 	  e->ref->u.ar.as = sym->as;
 	}
 
+      /* Expressions are assigned a default ts.type of BT_PROCEDURE in
+	 primary.c (match_actual_arg). If above code determines that it
+	 is a  variable instead, it needs to be resolved as it was not
+	 done at the beginning of this function.  */
+      if (gfc_resolve_expr (e) != SUCCESS)
+	return FAILURE;
+
     argument_list:
       /* Check argument list functions %VAL, %LOC and %REF.  There is
 	 nothing to do for %REF.  */
Index: gfortran.dg/pr32002.f90
===================================================================
--- gfortran.dg/pr32002.f90	(revision 0)
+++ gfortran.dg/pr32002.f90	(revision 0)
@@ -0,0 +1,44 @@
+! { dg-compile }
+!
+! Testcases from PR32002.
+!
+PROGRAM test_pr32002
+
+  CALL test_1()                       ! scalar/vector
+  CALL test_2()                       ! vector/vector
+  CALL test_3()                       ! matrix/vector
+  CALL test_4()                       ! matrix/matrix
+
+CONTAINS
+  ELEMENTAL FUNCTION f(x)
+    INTEGER, INTENT(in) :: x
+    INTEGER :: f
+    f = x
+  END FUNCTION
+
+  SUBROUTINE test_1()
+    INTEGER :: a = 0, b(2) = 0
+    a = f(b)                          ! { dg-error "Incompatible ranks" }
+    b = f(a)                          ! ok, set all array elements to f(a)
+  END SUBROUTINE
+
+  SUBROUTINE test_2()
+    INTEGER :: a(2) = 0, b(3) = 0
+    a = f(b(1:2))                     ! ok, slice, stride 1
+    a = f(b(1:3:2))                   ! ok, slice, stride 2
+    a = f(b)                          ! { dg-error "different shape" }
+  END SUBROUTINE
+
+  SUBROUTINE test_3()
+    INTEGER :: a(4) = 0, b(2,2) = 0
+    a = f(b)                          ! { dg-error "Incompatible ranks" }
+    a = f(RESHAPE(b, (/ 4 /)))        ! ok, same shape
+  END SUBROUTINE
+
+  SUBROUTINE test_4()
+    INTEGER :: a(2,2) = 0, b(3,3) = 0
+    a = f(b)                          ! { dg-error "Incompatible ranks" }
+    a = f(b(1:3, 1:2))                ! { dg-error "different shape" }
+    a = f(b(1:3:2, 1:3:2))            ! ok, same shape
+  END SUBROUTINE
+END PROGRAM

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