Patchwork [fortran] Further dependency improvements

login
register
mail settings
Submitter Thomas Koenig
Date Sept. 2, 2010, 7:32 p.m.
Message ID <1283455979.3554.0.camel@linux-fd1f.site>
Download mbox | patch
Permalink /patch/63522/
State New
Headers show

Comments

Thomas Koenig - Sept. 2, 2010, 7:32 p.m.
Ping?
After some more checking, I found that one useful case was missed:
Conversion functions weren't 'PURE.

This should also open the way to resolving PR 34145.

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.
	* intrinsics.c (add_conv):  Mark conversion functions as pure.
	(add_char_conversions):  Likewise.

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

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

Patch

Index: intrinsic.c
===================================================================
--- intrinsic.c	(Revision 163581)
+++ intrinsic.c	(Arbeitskopie)
@@ -3022,6 +3022,7 @@  add_conv (bt from_type, int from_kind, bt to_type,
   sym->simplify.cc = gfc_convert_constant;
   sym->standard = standard;
   sym->elemental = 1;
+  sym->pure = 1;
   sym->conversion = 1;
   sym->ts = to;
   sym->id = GFC_ISYM_CONVERSION;
@@ -3172,6 +3173,7 @@  add_char_conversions (void)
 	char_conversions[n].simplify.cc = gfc_convert_char_constant;
 	char_conversions[n].standard = GFC_STD_F2003;
 	char_conversions[n].elemental = 1;
+	char_conversions[n].pure = 1;
 	char_conversions[n].conversion = 0;
 	char_conversions[n].ts = to;
 	char_conversions[n].id = GFC_ISYM_CONVERSION;
Index: dependency.c
===================================================================
--- dependency.c	(Revision 163584)
+++ dependency.c	(Arbeitskopie)
@@ -353,39 +353,32 @@  gfc_dep_compare_expr (gfc_expr *e1, gfc_expr *e2)
       return -2;
 
     case EXPR_FUNCTION:
-      /* 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)
+      /* PURE functions can be compared for argument 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)
+	  || (e1->value.function.isym && e2->value.function.isym
+	      && e1->value.function.isym == e2->value.function.isym
+	      && e1->value.function.isym->pure))
 	{
+	  args1 = e1->value.function.actual;
+	  args2 = e2->value.function.actual;
 
-	case GFC_ISYM_REAL:
-	case GFC_ISYM_LOGICAL:
-	case GFC_ISYM_DBLE:
-	  break;
-
-	default:
-	  return -2;
+	  /* Compare the argument lists for equality.  */
+	  while (args1 && args2)
+	    {
+	      if (gfc_dep_compare_expr (args1->expr, args2->expr) != 0)
+		return -2;
+	      args1 = args1->next;
+	      args2 = args2->next;
+	    }
+	  return (args1 || args2) ? -2 : 0;
 	}
+      else
+	return -2;
+      break;
 
-      /* Compare the argument lists for equality.  */
-      while (args1 && args2)
-	{
-	  if (gfc_dep_compare_expr (args1->expr, args2->expr) != 0)
-	    return -2;
-	  args1 = args1->next;
-	  args2 = args2->next;
-	}
-      return (args1 || args2) ? -2 : 0;
-      
     default:
       return -2;
     }