From: Fritz Reese Date: Fri, 30 Sep 2016 11:42:31 +0000 (+0000) Subject: Fix ICE for maps with zero components. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c39747d24b7bc8b589393b5bf3e791cbe0176c7b;p=gcc.git Fix ICE for maps with zero components. 2016-09-30 Fritz Reese 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. From-SVN: r240652 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 03955d6ab96..19349a1a82b 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2016-09-30 Fritz Reese + + PR fortran/77764 + * interface.c (gfc_compare_union_types): Null-guard map components. + 2016-09-30 Fritz Reese PR fortran/77782 diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c index 3f6774e630b..04ad0e295f7 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/ChangeLog b/gcc/testsuite/ChangeLog index 841a6ef6e7f..3a359ba53ac 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-09-30 Fritz Reese + + PR fortran/77764 + * gfortran.dg/dec_union_8.f90: New testcase. + 2016-09-30 Fritz Reese PR fortran/77782 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 00000000000..2d856fc44ef --- /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