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

2020-03-04 Thread markeggleston at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93832

--- Comment #5 from markeggleston at gcc dot gnu.org ---
Created attachment 47968
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47968=edit
Incomplete patch

Please find att an incomplete patch.

program p
  type t
character :: a
integer :: b
integer :: c(t(1, 2, 3))
  end type
end

results in:

5 | integer :: c(t(1, 2, 3))
  | 1
Error: Expression at (1) must be of INTEGER type, found DERIVED
pr93832_2.f03:7:19:

5 | integer :: c(t(1, 2, 3))
  |   1
Error: Cannot convert INTEGER(4) to CHARACTER(1) at (1)

instead of an ICE

However the following:

program p
  type t
character :: a
integer :: b
integer :: c(t())
  end type
end

results in

5 | integer :: c(t())
  |  1
Error: No initializer for component 'a' given in the structure constructor at
(1)

I had hoped to report "Error: Expression at (1) must be of INTEGER type, found
DERIVED", the closest I managed was "Error: Expression at (1) must be of
INTEGER type, found UNKNOWN". Unfortunately that also resulted in duplicate and
spurious error messages.

As it stands the patch has the following side affect when running check-fortran

FAIL: gfortran.dg/typebound_call_25.f90   -O  (internal compiler error)
FAIL: gfortran.dg/typebound_call_25.f90   -O   (test for errors, line 32)
FAIL: gfortran.dg/typebound_call_25.f90   -O   (test for errors, line 33)
FAIL: gfortran.dg/typebound_call_25.f90   -O  (test for excess errors)
FAIL: gfortran.dg/typebound_proc_31.f90   -O  (internal compiler error)
FAIL: gfortran.dg/typebound_proc_31.f90   -O  (test for excess errors)
FAIL: gfortran.dg/typebound_proc_32.f90   -O  (internal compiler error)
FAIL: gfortran.dg/typebound_proc_32.f90   -O  (test for excess errors)


typebound_proc_31.f90:

! { dg-do compile }
!
! PR 59450: [OOP] ICE for type-bound-procedure expression in module procedure
interface
!
! Contributed by 

module classes

  implicit none

  type :: base_class
   contains
 procedure, nopass :: get_num
  end type

contains

  pure integer function get_num()
  end function

  function get_array( this ) result(array)
class(base_class), intent(in) :: this
integer, dimension( this%get_num() ) :: array
  end function

end module

produces this ICE:
f951: internal compiler error: check_restricted(): Unknown expression type
0x6c6ede gfc_report_diagnostic
../../gcc/gcc/fortran/error.c:782
0x6c85ca gfc_internal_error(char const*, ...)
../../gcc/gcc/fortran/error.c:1402
0x6cb6db check_restricted
../../gcc/gcc/fortran/expr.c:3428
0x6964b4 resolve_array_bound
../../gcc/gcc/fortran/array.c:378
0x697180 gfc_resolve_array_spec(gfc_array_spec*, int)
../../gcc/gcc/fortran/array.c:424
0x7406fe resolve_symbol
../../gcc/gcc/fortran/resolve.c:15832
0x7400c1 resolve_symbol
../../gcc/gcc/fortran/resolve.c:15247
0x75c6ab do_traverse_symtree
../../gcc/gcc/fortran/symbol.c:4147
0x742ccc resolve_types
../../gcc/gcc/fortran/resolve.c:17121
0x73e4dc gfc_resolve(gfc_namespace*)
../../gcc/gcc/fortran/resolve.c:17236
0x726aa4 gfc_parse_file()
../../gcc/gcc/fortran/parse.c:6447
0x77206f gfc_be_parse_file
../../gcc/gcc/fortran/f95-lang.c:210
Please submit a full bug report,

patch applied to master at f1a681a174cdfb82e62c246d6f4add9a25fc2e43

At this point I'm stuck and I currently don't have the knowledge to fix this.

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

2020-03-04 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93832

Jakub Jelinek  changed:

   What|Removed |Added

   Target Milestone|8.4 |8.5

--- Comment #4 from Jakub Jelinek  ---
GCC 8.4.0 has been released, adjusting target milestone.

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

2020-03-02 Thread markeggleston at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93832

markeggleston at gcc dot gnu.org changed:

   What|Removed |Added

 CC||markeggleston at gcc dot 
gnu.org

--- Comment #3 from markeggleston at gcc dot gnu.org ---
Using the patch comment 2 and the example program:

program p
   type t
  character :: a
  integer :: b
  integer :: c(t(1))
   end type
   type(t) :: z = t('a', 2, [3])
end

5 |   integer :: c(t(1))
  |1
Error: No initializer for component 'b' given in the structure constructor at
(1)

Adding a second initializer:

program p
   type t
  character :: a
  integer :: b
  integer :: c(t(1, "rubbish"))
   end type
   type(t) :: z = t('a', 2, [3])
end

5 |   integer :: c(t(1))
  |1
Error: No initializer for component 'c' given in the structure constructor at
(1)

There is no reporting of incompatible types i.e, integer(4) to character(1) and
character(7) to integer(4).

Finally if all initializers are given:

program p
   type t
  character :: a
  integer :: b
  integer :: c(t(1, "rubbish", 7.5))
   end type
   type(t) :: z = t('a', 2, [3])
end

The result is an ICE without a call stack:

gfortran: internal compiler error: Segmentation fault signal terminated program
f951
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.

The declaration of component c of the derived type t is intended to be an
array, if it is then I would expect the use of derived type to be illegal.

An error is given if a different derived type is used:

program p
   type t2
   end type
   type t
  character :: a
  integer :: b
  integer :: c(t2())
   end type
   type(t) :: z = t('a', 2, [3])
end


7 |   integer :: c(t2())
  |   1
Error: Expression at (1) must be of INTEGER type, found DERIVED

This is the error or something like it that should be reported when the derived
type t is used as the array spec.

Where the type t constructor is used in the declaration of type t I'm having
difficulty in stopping it from constructing a structure and consequently
resulting in an ICE.

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

2020-02-20 Thread kargl at gcc dot gnu.org
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, );
+ 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, _tail->val,
-   comp->ts.u.derived->attr.zero_comp
- ? _null : , true);
-  if (!m)
-goto cleanup;
+#define shorter gfc_convert_to_structure_constructor
+ m = shorter (NULL, comp->ts.u.derived, _tail->val,
+  comp->ts.u.derived->attr.zero_comp
+  ? _null : , 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

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

2020-02-20 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93832

Martin Liška  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2020-02-20
 CC||marxin at gcc dot gnu.org,
   ||tkoenig at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Martin Liška  ---
Confirmed, started with r8-6898-g04946c6b905572f3.

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

2020-02-20 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93832

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P4
   Target Milestone|--- |8.4