===================================================================
@@ -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)
{