public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, Fortran] PR fortran/77764 - ICE in is_anonymous_component
@ 2016-09-29 14:45 Fritz Reese
  2016-09-30  8:52 ` Andre Vehreschild
  0 siblings, 1 reply; 2+ messages in thread
From: Fritz Reese @ 2016-09-29 14:45 UTC (permalink / raw)
  To: gcc-patches, fortran

[-- Attachment #1: Type: text/plain, Size: 537 bytes --]

ICE in [1] is due to failure to null-guard map components in
gfc_compare_union_types. Attached is [obvious] fix - will commit soon
without complaints.

---
Fritz Reese

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77764

2016-09-29  Fritz Reese  <fritzoreese@gmail.com>

        Fix ICE for maps with zero components.

        PR fortran/77764
        * gcc/fortran/interface.c (gfc_compare_union_types): Null-guard map
        components.

        PR fortran/77764
        * gcc/testsuite/gfortran.dg/dec_union_8.f90: New testcase.

[-- Attachment #2: pr77764.patch --]
[-- Type: text/x-patch, Size: 1976 bytes --]

diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index 9d4e5e9..55923a3 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -526,6 +526,7 @@ int
 gfc_compare_union_types (gfc_symbol *un1, gfc_symbol *un2)
 {
   gfc_component *map1, *map2, *cmp1, *cmp2;
+  gfc_symbol *map1_t, *map2_t;
 
   if (un1->attr.flavor != FL_UNION || un2->attr.flavor != FL_UNION)
     return 0;
@@ -541,16 +542,26 @@ gfc_compare_union_types (gfc_symbol *un1, gfc_symbol *un2)
      we compare the maps sequentially. */
   for (;;)
   {
-    cmp1 = map1->ts.u.derived->components;
-    cmp2 = map2->ts.u.derived->components;
+    map1_t = map1->ts.u.derived;
+    map2_t = map2->ts.u.derived;
+
+    cmp1 = map1_t->components;
+    cmp2 = map2_t->components;
+
+    /* Protect against null components.  */
+    if (map1_t->attr.zero_comp != map2_t->attr.zero_comp)
+      return 0;
+
+    if (map1_t->attr.zero_comp)
+      return 1;
+
     for (;;)
     {
       /* No two fields will ever point to the same map type unless they are
          the same component, because one map field is created with its type
          declaration. Therefore don't worry about recursion here. */
       /* TODO: worry about recursion into parent types of the unions? */
-      if (compare_components (cmp1, cmp2,
-            map1->ts.u.derived, map2->ts.u.derived) == 0)
+      if (compare_components (cmp1, cmp2, map1_t, map2_t) == 0)
         return 0;
 
       cmp1 = cmp1->next;
diff --git a/gcc/testsuite/gfortran.dg/dec_union_8.f90 b/gcc/testsuite/gfortran.dg/dec_union_8.f90
new file mode 100644
index 0000000..2d856fc
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_union_8.f90
@@ -0,0 +1,21 @@
+! { dg-do compile }
+! { dg-options "-fdec-structure" }
+!
+! PR fortran/77764
+!
+! Test an ICE due to a map with zero components.
+!
+
+program p
+
+structure /s1/
+  union
+    map
+    end map
+    map
+      real :: a = 2.0
+    end map
+  end union
+end structure
+
+end

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH, Fortran] PR fortran/77764 - ICE in is_anonymous_component
  2016-09-29 14:45 [PATCH, Fortran] PR fortran/77764 - ICE in is_anonymous_component Fritz Reese
@ 2016-09-30  8:52 ` Andre Vehreschild
  0 siblings, 0 replies; 2+ messages in thread
From: Andre Vehreschild @ 2016-09-30  8:52 UTC (permalink / raw)
  To: Fritz Reese; +Cc: gcc-patches, fortran

Hi Fritz,

just out of curiosity: A structure typed can't be used for a class object? Like:

structure /T/
  integer :: something
end structure

class(T), allocatable :: foo

end

When the above *is* allowed then I miss some CLASS_DATA (...) in the code. If
not, everything is fine.

- Andre

On Thu, 29 Sep 2016 10:30:13 -0400
Fritz Reese <fritzoreese@gmail.com> wrote:

> ICE in [1] is due to failure to null-guard map components in
> gfc_compare_union_types. Attached is [obvious] fix - will commit soon
> without complaints.
> 
> ---
> Fritz Reese
> 
> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77764
> 
> 2016-09-29  Fritz Reese  <fritzoreese@gmail.com>
> 
>         Fix ICE for maps with zero components.
> 
>         PR fortran/77764
>         * gcc/fortran/interface.c (gfc_compare_union_types): Null-guard map
>         components.
> 
>         PR fortran/77764
>         * gcc/testsuite/gfortran.dg/dec_union_8.f90: New testcase.


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-30  8:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-29 14:45 [PATCH, Fortran] PR fortran/77764 - ICE in is_anonymous_component Fritz Reese
2016-09-30  8:52 ` Andre Vehreschild

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).