Fix ICE caused by union types comparing equal to structures.
authorFritz Reese <fritzoreese@gmail.com>
Fri, 30 Sep 2016 11:37:23 +0000 (11:37 +0000)
committerFritz Reese <foreese@gcc.gnu.org>
Fri, 30 Sep 2016 11:37:23 +0000 (11:37 +0000)
2016-09-30  Fritz Reese  <fritzoreese@gmail.com>

Fix ICE caused by union types comparing equal to structures.

PR fortran/77782
* gcc/fortran/interface.c (gfc_compare_derived_types): Use
gfc_compare_union_types to compare union types.

PR fortran/77782
* gcc/testsuite/gfortran.dg/dec_structure_16.f90: New testcase.

From-SVN: r240651

gcc/fortran/ChangeLog
gcc/fortran/interface.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/dec_structure_16.f90 [new file with mode: 0644]

index ea28ae55f9387d79b6af40083add45adcf2b9047..03955d6ab960caad815d53841e6269a050a5f15a 100644 (file)
@@ -1,3 +1,9 @@
+2016-09-30  Fritz Reese  <fritzoreese@gmail.com>
+
+       PR fortran/77782
+       * interface.c (gfc_compare_derived_types): Use gfc_compare_union_types
+       to compare union types.
+
 2016-09-30  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        * trans-array.c (gfc_array_allocate): Use the token from coarray's
index 5883e390d31024ef991e30e1d9f6b5a7446652ed..3f6774e630b93ff4c23fb757d7ec97c88f2706fa 100644 (file)
@@ -589,6 +589,10 @@ gfc_compare_derived_types (gfc_symbol *derived1, gfc_symbol *derived2)
 
   gcc_assert (derived1 && derived2);
 
+  /* Compare UNION types specially.  */
+  if (derived1->attr.flavor == FL_UNION || derived2->attr.flavor == FL_UNION)
+    return gfc_compare_union_types (derived1, derived2);
+
   /* Special case for comparing derived types across namespaces.  If the
      true names and module names are the same and the module name is
      nonnull, then they are equal.  */
index 9e8204174bc97c0dd3f99a70ff591e4b916b1c01..841a6ef6e7fab486322d664b8156c047eabd571b 100644 (file)
@@ -1,3 +1,8 @@
+2016-09-30  Fritz Reese  <fritzoreese@gmail.com>
+
+       PR fortran/77782
+       * gfortran.dg/dec_structure_16.f90: New testcase.
+
 2016-09-30  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        * gfortran.dg/coarray_allocate_10.f08: New test.
diff --git a/gcc/testsuite/gfortran.dg/dec_structure_16.f90 b/gcc/testsuite/gfortran.dg/dec_structure_16.f90
new file mode 100644 (file)
index 0000000..f9b2671
--- /dev/null
@@ -0,0 +1,35 @@
+! { dg-do compile }
+! { dg-options "-fdec-structure" }
+!
+! PR fortran/77782
+!
+! Test an ICE where a union might be considered equal to a structure,
+! causing the union's backend_decl to be replaced with that of the structure.
+!
+
+program p
+
+structure /s1/
+  union
+    map
+      integer(4) a
+      end map
+    map
+      real(4) b
+    end map
+  end union
+end structure
+
+structure /s2/
+  union ! regression: if this union == s1, we ICE in gfc_get_union_type
+    map
+      integer(2) x, y
+      integer(4) z
+    end map
+  end union
+end structure
+
+record /s1/ r1
+r1.a = 0
+
+end