[Bug fortran/93832] [8/9/10 Regression] ICE in gfc_convert_to_structure_constructor, at fortran/primary.c:3100

kargl at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Feb 20 19:10:00 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93832

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #2 from kargl at gcc dot gnu.org ---
Patch is against svn r280157.

The 1st chuck suppress output of the error message if any
other error had previously been emitted.

The 2nd chuck is the actual fix for this PR.  gfortran
should not dereference a NULL pointer.

The 3rd chuck is a large whitespace cleanup.

The last bit adjusts a testcase that is effected by the
1st chunk.

Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c       (revision 280157)
+++ gcc/fortran/primary.c       (working copy)
@@ -2979,8 +2979,11 @@ build_actual_constructor (gfc_structure_ctor_component
            }
          else if (!comp->attr.artificial)
            {
-             gfc_error ("No initializer for component %qs given in the"
-                        " structure constructor at %C", comp->name);
+             int ecnt;
+             gfc_get_errors (NULL, &ecnt);
+             if (ecnt == 0)
+               gfc_error ("No initializer for component %qs given in the"
+                          " structure constructor at %C", comp->name);
              return false;
            }
        }
@@ -3097,6 +3100,7 @@ gfc_convert_to_structure_constructor (gfc_expr *e, gfc
       if (this_comp->ts.type == BT_CHARACTER && !this_comp->attr.allocatable
          && this_comp->ts.u.cl && this_comp->ts.u.cl->length
          && this_comp->ts.u.cl->length->expr_type == EXPR_CONSTANT
+         && actual->expr
          && actual->expr->ts.type == BT_CHARACTER
          && actual->expr->expr_type == EXPR_CONSTANT)
        {
@@ -3161,35 +3165,36 @@ gfc_convert_to_structure_constructor (gfc_expr *e, gfc
          goto cleanup;
        }

-          /* If not explicitly a parent constructor, gather up the components
-             and build one.  */
-          if (comp && comp == sym->components
-                && sym->attr.extension
-               && comp_tail->val
-                && (!gfc_bt_struct (comp_tail->val->ts.type)
-                      ||
-                    comp_tail->val->ts.u.derived != this_comp->ts.u.derived))
-            {
-              bool m;
-             gfc_actual_arglist *arg_null = NULL;
+      /* If not explicitly a parent constructor, gather up the components
+        and build one.  */
+      if (comp && comp == sym->components
+         && sym->attr.extension
+         && comp_tail->val
+         && (!gfc_bt_struct (comp_tail->val->ts.type)
+             || comp_tail->val->ts.u.derived != this_comp->ts.u.derived))
+       {
+         bool m;
+         gfc_actual_arglist *arg_null = NULL;

-             actual->expr = comp_tail->val;
-             comp_tail->val = NULL;
+         actual->expr = comp_tail->val;
+         comp_tail->val = NULL;

-              m = gfc_convert_to_structure_constructor (NULL,
-                                       comp->ts.u.derived, &comp_tail->val,
-                                       comp->ts.u.derived->attr.zero_comp
-                                         ? &arg_null : &actual, true);
-              if (!m)
-                goto cleanup;
+#define shorter gfc_convert_to_structure_constructor
+         m = shorter (NULL, comp->ts.u.derived, &comp_tail->val,
+                      comp->ts.u.derived->attr.zero_comp
+                      ? &arg_null : &actual, true);
+#undef shorter

-             if (comp->ts.u.derived->attr.zero_comp)
-               {
-                 comp = comp->next;
-                 continue;
-               }
-            }
+         if (!m)
+           goto cleanup;

+         if (comp->ts.u.derived->attr.zero_comp)
+           {
+             comp = comp->next;
+             continue;
+           }
+       }
+
       if (comp)
        comp = comp->next;
       if (parent && !comp)
@@ -3239,7 +3244,8 @@ gfc_convert_to_structure_constructor (gfc_expr *e, gfc
     *arglist = actual;
   return true;

-  cleanup:
+cleanup:
+
   gfc_current_locus = old_locus;

   for (comp_iter = comp_head; comp_iter; )
Index: gcc/testsuite/gfortran.dg/structure_constructor_6.f03
===================================================================
--- gcc/testsuite/gfortran.dg/structure_constructor_6.f03       (revision
280157)
+++ gcc/testsuite/gfortran.dg/structure_constructor_6.f03       (working copy)
@@ -15,6 +15,5 @@ PROGRAM test
   TYPE(basics_t) :: basics

   basics = basics_t (i = 42) ! { dg-error "No initializer for component 'r'" }
-  basics = basics_t (42) ! { dg-error "No initializer for component 'r'" }

 END PROGRAM test


More information about the Gcc-bugs mailing list