This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gfortran] Comparing array specs
- From: Paul Brook <paul at nowt dot org>
- To: "gcc-g95 List" <gcc-g95-devel at lists dot sourceforge dot net>,"gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 16 Sep 2003 22:15:02 +0100
- Subject: [gfortran] Comparing array specs
Patch below allows array specs larget than sizeof(int) to be compared.
Applied to tree-ssa branch.
Paul
2003-09-16 Paul Brook <paul@nowt.org>
* array.c (compare_bounds): New function.
(gfc_compare_array_spec): Use it.
diff -urpxCVS clean/tree-ssa/gcc/fortran/array.c gcc/gcc/fortran/array.c
--- clean/tree-ssa/gcc/fortran/array.c 2003-08-02 01:25:05.000000000 +0100
+++ gcc/gcc/fortran/array.c 2003-09-16 22:01:12.000000000 +0100
@@ -489,13 +489,32 @@ gfc_copy_array_spec (gfc_array_spec * sr
return dest;
}
+/* Returns nonzero if the two expressions are equal. Only handles integer
+ constants. */
-/* Compares two array specifications. */
+static int
+compare_bounds (gfc_expr * bound1, gfc_expr * bound2)
+{
+ if (bound1 == NULL || bound2 == NULL
+ || bound1->expr_type != EXPR_CONSTANT
+ || bound2->expr_type != EXPR_CONSTANT
+ || bound1->ts.type != BT_INTEGER
+ || bound2->ts.type != BT_INTEGER)
+ gfc_internal_error ("gfc_compare_array_spec(): Array spec clobbered");
+
+ if (mpz_cmp (bound1->value.integer, bound2->value.integer) == 0)
+ return 1;
+ else
+ return 0;
+}
+
+/* Compares two array specifications. They must be constant or deferred
+ shape. */
int
gfc_compare_array_spec (gfc_array_spec * as1, gfc_array_spec * as2)
{
- int i, a1, a2;
+ int i;
if (as1 == NULL && as2 == NULL)
return 1;
@@ -515,26 +534,14 @@ gfc_compare_array_spec (gfc_array_spec *
if (as1->type == AS_EXPLICIT)
for (i = 0; i < as1->rank; i++)
{
- if (gfc_extract_int (as1->lower[i], &a1) != NULL)
- goto error;
- if (gfc_extract_int (as2->lower[i], &a2) != NULL)
- goto error;
- if (a1 != a2)
+ if (compare_bounds (as1->lower[i], as2->lower[i]) == 0)
return 0;
- if (gfc_extract_int (as1->upper[i], &a1) != NULL)
- goto error;
- if (gfc_extract_int (as2->upper[i], &a2) != NULL)
- goto error;
- if (a1 != a2)
+ if (compare_bounds (as1->upper[i], as2->upper[i]) == 0)
return 0;
}
return 1;
-
-error:
- gfc_internal_error ("gfc_compare_array_spec(): Array spec clobbered");
- /* Not reached */
}