[gcc/devel/c++-coroutines] Save typespec for empty array constructor.

Iain D Sandoe iains@gcc.gnu.org
Fri Jan 17 12:47:00 GMT 2020


https://gcc.gnu.org/g:d636017868e7416675bb07491eb13ff4c8536702

commit d636017868e7416675bb07491eb13ff4c8536702
Author: Thomas Koenig <tkoenig@gcc.gnu.org>
Date:   Thu Jan 9 20:57:33 2020 +0000

    Save typespec for empty array constructor.
    
    2020-01-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
    
    	PR fortran/65428
    	* array.c (empty_constructor): New variable.
    	(empty_ts): New variable.
    	(expand_constructor): Save typespec in empty_ts.
    	Unset empty_constructor if there is an element.
    	(gfc_expand_constructor): Initialize empty_constructor
    	and empty_ts.  If there was no explicit constructor
    	type and the constructor is empty, take the type from
    	empty_ts.
    
    2020-01-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
    
    	PR fortran/65428
    	* gfortran.dg/zero_sized_11.f90: New test.
    
    From-SVN: r280063

Diff:
---
 gcc/fortran/ChangeLog                       | 12 ++++++++++++
 gcc/fortran/array.c                         | 18 ++++++++++++++++++
 gcc/testsuite/ChangeLog                     |  6 ++++++
 gcc/testsuite/gfortran.dg/zero_sized_11.f90 |  8 ++++++++
 gcc/testsuite/gfortran.dg/zero_sized_12.f90 | 17 +++++++++++++++++
 5 files changed, 61 insertions(+)

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 80d37a3..c3ca3de 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,15 @@
+2020-01-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+	PR fortran/65428
+	* array.c (empty_constructor): New variable.
+	(empty_ts): New variable.
+	(expand_constructor): Save typespec in empty_ts.
+	Unset empty_constructor if there is an element.
+	(gfc_expand_constructor): Initialize empty_constructor
+	and empty_ts.  If there was no explicit constructor
+	type and the constructor is empty, take the type from
+	empty_ts.
+
 2020-01-09  Tobias Burnus  <tobias@codesourcery.com>
 
 	PR fortran/84135
diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index 157acb8..c873cf2 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -1759,6 +1759,11 @@ cleanup:
   return t;
 }
 
+/* Variables for noticing if all constructors are empty, and
+   if any of them had a type.  */
+
+static bool empty_constructor;
+static gfc_typespec empty_ts;
 
 /* Expand a constructor into constant constructors without any
    iterators, calling the work function for each of the expanded
@@ -1782,6 +1787,9 @@ expand_constructor (gfc_constructor_base base)
 
       e = c->expr;
 
+      if (empty_constructor)
+	empty_ts = e->ts;
+
       if (e->expr_type == EXPR_ARRAY)
 	{
 	  if (!expand_constructor (e->value.constructor))
@@ -1790,6 +1798,7 @@ expand_constructor (gfc_constructor_base base)
 	  continue;
 	}
 
+      empty_constructor = false;
       e = gfc_copy_expr (e);
       if (!gfc_simplify_expr (e, 1))
 	{
@@ -1873,6 +1882,8 @@ gfc_expand_constructor (gfc_expr *e, bool fatal)
 
   iter_stack = NULL;
 
+  empty_constructor = true;
+  gfc_clear_ts (&empty_ts);
   current_expand.expand_work_function = expand;
 
   if (!expand_constructor (e->value.constructor))
@@ -1882,6 +1893,13 @@ gfc_expand_constructor (gfc_expr *e, bool fatal)
       goto done;
     }
 
+  /* If we don't have an explicit constructor type, and there
+     were only empty constructors, then take the type from
+     them.  */
+
+  if (constructor_ts.type == BT_UNKNOWN && empty_constructor)
+    e->ts = empty_ts;
+
   gfc_constructor_free (e->value.constructor);
   e->value.constructor = current_expand.base;
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0cf4394..0c1dee3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2020-01-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+	PR fortran/65428
+	* gfortran.dg/zero_sized_11.f90: New test.
+	* gfortran.dg/zero_sized_12.f90: New test.
+
 2020-01-09  Richard Sandiford  <richard.sandiford@arm.com>
 
 	* g++.target/aarch64/sve/acle/general-c++/mul_lane_1.c: New test.
diff --git a/gcc/testsuite/gfortran.dg/zero_sized_11.f90 b/gcc/testsuite/gfortran.dg/zero_sized_11.f90
new file mode 100644
index 0000000..35f7534
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/zero_sized_11.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR 65428 - this used to ICE.  Original test case by FX Coudert.
+program p
+   integer :: i
+   print *, [shape(1)]
+   print *, [[ integer :: ]]
+   print *, (/ (/ (i, i=1,0) /) /)
+end
diff --git a/gcc/testsuite/gfortran.dg/zero_sized_12.f90 b/gcc/testsuite/gfortran.dg/zero_sized_12.f90
new file mode 100644
index 0000000..592c19f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/zero_sized_12.f90
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! PR 65248 - this used to ICE. Test case by Tobias Burnus.
+
+program main
+  
+! C7110  (R770) If type-spec is omitted, each ac-value expression in the
+! array-constructor shall have the same declared type and kind type parameters
+
+! Should be fine as there is either no or only one ac-value:
+print *, [[integer ::],[real::]]
+print *, [[integer ::],[real::], [1], [real ::]]
+print *, [[integer ::],[real::], ["ABC"], [real ::]] // "ABC"
+print *, [integer :: [integer ::],[real::]]
+
+! OK - accepted
+print *, [integer :: [1],[1.0]]
+end



More information about the Gcc-cvs mailing list