This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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] Further dependency improvements


Hello world,

now I'm back from my holiday, here is another round of dependency
improvements.  This patch is fairly self-explanatory.

OK for trunk?

	Thomas

2010-08-28  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/45159
	* dependency.c (gfc_deb_compare_expr):  Compare equal for equal
	arglists for pure user functions, or for those intrinsic
	functions which are also pure.

2010-08-28  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/45159
	* gfortran.dg/dependency_34.f90:  New test.

Index: dependency.c
===================================================================
--- dependency.c	(Revision 163584)
+++ dependency.c	(Arbeitskopie)
@@ -353,29 +353,77 @@ gfc_dep_compare_expr (gfc_expr *e1, gfc_expr *e2)
       return -2;
 
     case EXPR_FUNCTION:
+
+      /* PURE user functions can be compared for equality.  */
+      if (e1->value.function.esym && e2->value.function.esym
+	  && e1->value.function.esym == e2->value.function.esym
+	  && e1->value.function.esym->result->attr.pure)
+	goto compare_arglists;
+      
       /* We can only compare calls to the same intrinsic function.  */
-      if (e1->value.function.isym == 0 || e2->value.function.isym == 0
-	  || e1->value.function.isym != e2->value.function.isym)
-	return -2;
-
-      args1 = e1->value.function.actual;
-      args2 = e2->value.function.actual;
-
-      /* We should list the "constant" intrinsic functions.  Those
-	 without side-effects that provide equal results given equal
-	 argument lists.  */
-      switch (e1->value.function.isym->id)
+      if (e1->value.function.isym && e2->value.function.isym
+	  && e1->value.function.isym == e2->value.function.isym)
 	{
+	  switch (e1->value.function.isym->id)
+	    {
 
-	case GFC_ISYM_REAL:
-	case GFC_ISYM_LOGICAL:
-	case GFC_ISYM_DBLE:
-	  break;
+	      /* List of intrinsic functions with side effects or which
+		 may compare unequal for equal arguments.  */
+	    case GFC_ISYM_CHDIR:
+	    case GFC_ISYM_CHMOD:
+	    case GFC_ISYM_DTIME:
+	    case GFC_ISYM_ETIME:
+	    case GFC_ISYM_FDATE:
+	    case GFC_ISYM_FGET:
+	    case GFC_ISYM_FGETC:
+	    case GFC_ISYM_FNUM:
+	    case GFC_ISYM_FPUT:
+	    case GFC_ISYM_FPUTC:
+	    case GFC_ISYM_FSTAT:
+	    case GFC_ISYM_FTELL:
+	    case GFC_ISYM_GETCWD:
+	    case GFC_ISYM_GETGID:
+	    case GFC_ISYM_GETPID:
+	    case GFC_ISYM_GETUID:
+	    case GFC_ISYM_HOSTNM:
+	    case GFC_ISYM_IERRNO:
+	    case GFC_ISYM_IRAND:
+	    case GFC_ISYM_IMAGE_INDEX:
+	    case GFC_ISYM_ISATTY:
+	    case GFC_ISYM_KILL:
+	    case GFC_ISYM_LINK:
+	    case GFC_ISYM_MALLOC:
+	    case GFC_ISYM_MCLOCK:
+	    case GFC_ISYM_MCLOCK8:
+	    case GFC_ISYM_MOVE_ALLOC:
+	    case GFC_ISYM_NUMIMAGES:
+	    case GFC_ISYM_RAND:
+	    case GFC_ISYM_RENAME:
+	    case GFC_ISYM_SECNDS:
+	    case GFC_ISYM_SECOND:
+	    case GFC_ISYM_SIGNAL:
+	    case GFC_ISYM_STAT:
+	    case GFC_ISYM_SYMLINK:
+	    case GFC_ISYM_SYMLNK:
+	    case GFC_ISYM_SYSTEM:
+	    case GFC_ISYM_THIS_IMAGE:
+	    case GFC_ISYM_TIME:
+	    case GFC_ISYM_TIME8:
+	    case GFC_ISYM_TTYNAM:
+	    case GFC_ISYM_UMASK:
+	    case GFC_ISYM_UNLINK:
+	      return -2;
 
-	default:
-	  return -2;
+	  default:
+	    break;
+	  }
 	}
 
+    compare_arglists:
+
+      args1 = e1->value.function.actual;
+      args2 = e2->value.function.actual;
+
       /* Compare the argument lists for equality.  */
       while (args1 && args2)
 	{
! { dg-do compile }
! { dg-options "-Warray-temporaries" }
module foo
  implicit none
contains
  integer pure  function bar(i,j)
    integer, intent(in) :: i,j
    bar = 3 - i + 1 * abs(i) + j
  end function bar
end module foo

program main
  use foo
  implicit none
  real a(10)
  integer :: i
  read (*,*) a, i
  a(i:abs(i)) = a(i:abs(i))
  a(bar(i,i+2):2) = a(bar(i,i+2):2)
end program main
! { dg-final { cleanup-modules "foo" } }

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