aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven G. Kargl <kargl@gcc.gnu.org>2016-09-08 22:33:10 +0000
committerSteven G. Kargl <kargl@gcc.gnu.org>2016-09-08 22:33:10 +0000
commit2cf0ff9806714eacef91f759b3c7422a4491e695 (patch)
tree6c5ce11b8f25d62eea31762763a992aed00e4ed6
parent20b6cf0194331045a8afa61ebf6432bb18f1ae87 (diff)
downloadgcc-2cf0ff9806714eacef91f759b3c7422a4491e695.zip
gcc-2cf0ff9806714eacef91f759b3c7422a4491e695.tar.gz
gcc-2cf0ff9806714eacef91f759b3c7422a4491e695.tar.bz2
re PR fortran/69514 (ICE with nested array constructor)
2016-09-08 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/69514 * array.c (gfc_match_array_constructor): If type-spec is present, walk the array constructor performing possible conversions for numeric types. 2016-09-08 Steven G. Kargl <kargl@gcc.gnu.org> Louis Krupp <lkrupp@gcc.gnu.org> PR fortran/69514 * gfortran.dg/pr69514_1.f90: New test. * gfortran.dg/pr69514_2.f90: New test. Co-Authored-By: Louis Krupp <lkrupp@gcc.gnu.org> From-SVN: r240039
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/array.c11
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gfortran.dg/pr69514_1.f905
-rw-r--r--gcc/testsuite/gfortran.dg/pr69514_2.f9049
5 files changed, 77 insertions, 2 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index a0be074..53c6e2d 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,10 @@
+2016-09-08 Steven G. Kargl <kargl@gcc.gnu.org>
+
+ PR fortran/69514
+ * array.c (gfc_match_array_constructor): If type-spec is present,
+ walk the array constructor performing possible conversions for
+ numeric types.
+
2016-09-08 Jakub Jelinek <jakub@redhat.com>
PR fortran/77500
diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index 03c8b17..48a7250 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -1089,6 +1089,7 @@ match_array_cons_element (gfc_constructor_base *result)
match
gfc_match_array_constructor (gfc_expr **result)
{
+ gfc_constructor *c;
gfc_constructor_base head, new_cons;
gfc_undo_change_set changed_syms;
gfc_expr *expr;
@@ -1194,8 +1195,6 @@ done:
be converted. See PR fortran/67803. */
if (ts.type == BT_CHARACTER)
{
- gfc_constructor *c;
-
c = gfc_constructor_first (head);
for (; c; c = gfc_constructor_next (c))
{
@@ -1218,6 +1217,14 @@ done:
}
}
}
+
+ /* Walk the constructor and ensure type conversion for numeric types. */
+ if (gfc_numeric_ts (&ts))
+ {
+ c = gfc_constructor_first (head);
+ for (; c; c = gfc_constructor_next (c))
+ gfc_convert_type (c->expr, &ts, 1);
+ }
}
else
expr = gfc_get_array_expr (BT_UNKNOWN, 0, &where);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7cbb87a..d841cac 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2016-09-08 Steven G. Kargl <kargl@gcc.gnu.org>
+ Louis Krupp <lkrupp@gcc.gnu.org>
+
+ PR fortran/69514
+ * gfortran.dg/pr69514_1.f90: New test.
+ * gfortran.dg/pr69514_2.f90: New test.
+
2016-09-08 Jakub Jelinek <jakub@redhat.com>
PR fortran/77500
diff --git a/gcc/testsuite/gfortran.dg/pr69514_1.f90 b/gcc/testsuite/gfortran.dg/pr69514_1.f90
new file mode 100644
index 0000000..d72a450
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr69514_1.f90
@@ -0,0 +1,5 @@
+! { dg-do run }
+program foo
+ real, parameter :: x(3) = 2.0 * [real :: 1, 2, 3 ]
+ if (any(x /= [2., 4., 6.])) call abort
+end program foo
diff --git a/gcc/testsuite/gfortran.dg/pr69514_2.f90 b/gcc/testsuite/gfortran.dg/pr69514_2.f90
new file mode 100644
index 0000000..0a5e816
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr69514_2.f90
@@ -0,0 +1,49 @@
+! { dg-do run }
+program p
+ implicit none
+
+ real , parameter :: arr(3) = [ real :: 2, 2.5, (1.5, 2.5) ]
+ real , parameter :: ari(3) = [ integer :: 2, 2.5, (1.5, 2.5) ]
+ real , parameter :: arc(3) = [ complex :: 2, 2.5, (1.5, 2.5) ]
+ integer, parameter :: air(3) = [ real :: 2, 2.5, (1.5, 2.5) ]
+ integer, parameter :: aii(3) = [ integer :: 2, 2.5, (1.5, 2.5) ]
+ integer, parameter :: aic(3) = [ complex :: 2, 2.5, (1.5, 2.5) ]
+ complex, parameter :: acr(3) = [ real :: 2, 2.5, (1.5, 2.5) ]
+ complex, parameter :: aci(3) = [ integer :: 2, 2.5, (1.5, 2.5) ]
+ complex, parameter :: acc(3) = [ complex :: 2, 2.5, (1.5, 2.5) ]
+
+ real , parameter :: mrr(3) = 4.5 * [ real :: 2, 2.5, (3.5, 4.0) ]
+ real , parameter :: mri(3) = 4.5 * [ integer :: 2, 2.5, (3.5, 4.0) ]
+ real , parameter :: mrc(3) = 4.5 * [ complex :: 2, 2.5, (3.5, 4.0) ]
+ integer, parameter :: mir(3) = 4 * [ real :: 2, 2.5, (3.5, 4.0) ]
+ integer, parameter :: mii(3) = 4 * [ integer :: 2, 2.5, (3.5, 4.0) ]
+ integer, parameter :: mic(3) = 4 * [ complex :: 2, 2.5, (3.5, 4.0) ]
+ complex, parameter :: mcr(3) = (4.5, 5.5) * [ real :: 2, 2.5, (3.5, 4.0) ]
+ complex, parameter :: mci(3) = (4.5, 5.5) * [ integer :: 2, 2.5, (3.5, 4.0) ]
+ complex, parameter :: mcc(3) = (4.5, 5.5) * [ complex :: 2, 2.5, (3.5, 4.0) ]
+
+ if (any(arr /= [2.00, 2.50, 1.50])) call abort
+ if (any(ari /= [2.00, 2.00, 1.00])) call abort
+ if (any(arc /= [2.00, 2.50, 1.50])) call abort
+
+ if (any(air /= [2, 2, 1])) call abort
+ if (any(aii /= [2, 2, 1])) call abort
+ if (any(aic /= [2, 2, 1])) call abort
+
+ if (any(acr /= [(2.00, 0.00), (2.50, 0.00), (1.50, 0.00)])) call abort
+ if (any(aci /= [(2.00, 0.00), (2.00, 0.00), (1.00, 0.00)])) call abort
+ if (any(acc /= [(2.00, 0.00), (2.50, 0.00), (1.50, 2.50)])) call abort
+
+ if (any(mrr /= [9.00, 11.25, 15.75])) call abort
+ if (any(mri /= [9.00, 9.00, 13.50])) call abort
+ if (any(mrc /= [9.00, 11.25, 15.75])) call abort
+
+ if (any(mir /= [8, 10, 14])) call abort
+ if (any(mii /= [8, 8, 12])) call abort
+ if (any(mic /= [8, 10, 14])) call abort
+
+ if (any(mcr /= [(9.00, 11.00), (11.25, 13.75), (15.75, 19.25)])) call abort
+ if (any(mci /= [(9.00, 11.00), ( 9.00, 11.00), (13.50, 16.50)])) call abort
+ if (any(mcc /= [(9.00, 11.00), (11.25, 13.75), (-6.25, 37.25)])) call abort
+
+end program p