[Bug fortran/69514] ICE with nested array constructor

2016-01-27 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69514

Dominique d'Humieres  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-01-27
 Ever confirmed|0   |1

--- Comment #1 from Dominique d'Humieres  ---
Confirmed from 4.8 up to trunk (6.0).

[Bug fortran/69514] ICE with nested array constructor

2016-02-02 Thread gerhard.steinmetz.fort...@t-online.de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69514

--- Comment #2 from Gerhard Steinmetz  
---
Test case from comment 0 can be reduced to e.g.

$ cat z3.f90
program p
   real, parameter :: w(2) = [real :: 0, 3.0*[real :: 2]]
   print *, w
end program

$ gfortran-6 -c z3.f90
f951: internal compiler error: Segmentation fault


Another variation is to revers operands.
As known, this compiles and runs, but gives WRONG results.

$ cat z4.f90
program p
   real, parameter :: w(2) = [real :: 0, [real :: 2]*3.0]
   print *, w
end program

$ gfortran-6 z4.f90
$ a.out
   0.   0.


Analogous for other operations, other intrinsic types, other 
combinations - look up especially in attached files of pr66193.
Some variants segfault, some compile and run silently wrong.

This theme is known from pr66193.

[Bug fortran/69514] ICE with nested array constructor

2016-09-03 Thread lkrupp at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69514

lkrupp at gcc dot gnu.org changed:

   What|Removed |Added

 CC||lkrupp at gcc dot gnu.org

--- Comment #3 from lkrupp at gcc dot gnu.org ---
This slightly simpler program reproduces the problem at version 7.0:

program p
 implicit none

 real, parameter :: w(1) = 3.0 * [ real :: 2 ]

 write(*,*) w

end program p

The problem seems to be that the constructed array is REAL (in ts.type field)
and its element 2 is an INTEGER, but the 3.0 and 2 are multiplied (in
gfc_arith_times) as if both were REAL.

[Bug fortran/69514] ICE with nested array constructor

2016-09-03 Thread lkrupp at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69514

--- Comment #4 from lkrupp at gcc dot gnu.org ---
This patch is a kludge.  I don't recommend it.  But it does fix at least one of
the test cases, it passes the test suite, and it might point to a proper
solution:

Index: arith.c
===
--- arith.c (revision 239966)
+++ arith.c (working copy)
@@ -1326,7 +1326,21 @@ reduce_binary_ca (arith (*eval) (gfc_expr *, gfc_e
   for (c = gfc_constructor_first (head); c; c = gfc_constructor_next (c))
 {
   if (c->expr->expr_type == EXPR_CONSTANT)
-   rc = eval (op1, c->expr, &r);
+   {
+ /* The conversion *should* be done only if necessary. */
+ gfc_expr temp;
+
+ temp.expr_type = EXPR_OP;
+ gfc_clear_ts (&temp.ts);
+
+ temp.value.op.op = INTRINSIC_PLUS; /* Arbitrary */
+ temp.value.op.op1 = op1;
+ temp.value.op.op2 = c->expr;
+
+ gfc_type_convert_binary (&temp,
+   warn_conversion || warn_conversion_extra);
+
+ rc = eval (op1, c->expr, &r);
+   }
   else
rc = reduce_binary_ca (eval, op1, c->expr, &r);

[Bug fortran/69514] ICE with nested array constructor

2016-09-05 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69514

kargl at gcc dot gnu.org changed:

   What|Removed |Added

 CC||kargl at gcc dot gnu.org

--- Comment #5 from kargl at gcc dot gnu.org ---
(In reply to lkrupp from comment #4)
> This patch is a kludge.  I don't recommend it.  But it does fix at least one
> of the test cases, it passes the test suite, and it might point to a proper
> solution:
> 
> Index: arith.c
> ===
> --- arith.c (revision 239966)
> +++ arith.c (working copy)
> @@ -1326,7 +1326,21 @@ reduce_binary_ca (arith (*eval) (gfc_expr *, gfc_e
>for (c = gfc_constructor_first (head); c; c = gfc_constructor_next (c))
>  {
>if (c->expr->expr_type == EXPR_CONSTANT)
> -   rc = eval (op1, c->expr, &r);
> +   {
> + /* The conversion *should* be done only if necessary. */
> + gfc_expr temp;
> +
> + temp.expr_type = EXPR_OP;
> + gfc_clear_ts (&temp.ts);
> +
> + temp.value.op.op = INTRINSIC_PLUS; /* Arbitrary */
> + temp.value.op.op1 = op1;
> + temp.value.op.op2 = c->expr;
> +
> + gfc_type_convert_binary (&temp,
> +   warn_conversion || warn_conversion_extra);
> +
> + rc = eval (op1, c->expr, &r);
> +   }
>else
> rc = reduce_binary_ca (eval, op1, c->expr, &r);

I agree the patch is a kludge. :-)

For a constructor with a typespec, gfortran should probably
walk the constructor and ensure type conversion for numeric
data types.  The patch does that.

Index: gcc/fortran/array.c
===
--- gcc/fortran/array.c (revision 239797)
+++ gcc/fortran/array.c (working copy)
@@ -1089,6 +1089,7 @@ match_array_cons_element (gfc_constructo
 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);
Index: gcc/testsuite/gfortran.dg/pr69514.f90
===
--- gcc/testsuite/gfortran.dg/pr69514.f90   (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr69514.f90   (working copy)
@@ -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

[Bug fortran/69514] ICE with nested array constructor

2016-09-06 Thread lkrupp at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69514

--- Comment #6 from lkrupp at gcc dot gnu.org ---
Here's a test case for the paranoid among us:

! { 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

[Bug fortran/69514] ICE with nested array constructor

2016-09-08 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69514

--- Comment #7 from kargl at gcc dot gnu.org ---
Author: kargl
Date: Thu Sep  8 22:33:10 2016
New Revision: 240039

URL: https://gcc.gnu.org/viewcvs?rev=240039&root=gcc&view=rev
Log:
2016-09-08  Steven G. Kargl  

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  
Louis Krupp  

PR fortran/69514
* gfortran.dg/pr69514_1.f90: New test.
* gfortran.dg/pr69514_2.f90: New test.

Added:
trunk/gcc/testsuite/gfortran.dg/pr69514_1.f90
trunk/gcc/testsuite/gfortran.dg/pr69514_2.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/array.c
trunk/gcc/testsuite/ChangeLog

[Bug fortran/69514] ICE with nested array constructor

2016-09-08 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69514

kargl at gcc dot gnu.org changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED
   Assignee|unassigned at gcc dot gnu.org  |kargl at gcc dot gnu.org
   Target Milestone|--- |7.0

--- Comment #8 from kargl at gcc dot gnu.org ---
Fixed on trunk.

[Bug fortran/69514] ICE with nested array constructor

2016-09-29 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69514

--- Comment #9 from kargl at gcc dot gnu.org ---
Author: kargl
Date: Thu Sep 29 18:35:49 2016
New Revision: 240628

URL: https://gcc.gnu.org/viewcvs?rev=240628&root=gcc&view=rev
Log:
2016-09-29  Steven G. Kargl  

Backport from trunk
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-29  Steven G. Kargl  
Louis Krupp  

Backport from trunk
PR fortran/69514
* gfortran.dg/pr69514_1.f90: New test.
* gfortran.dg/pr69514_2.f90: New test.

Added:
branches/gcc-5-branch/gcc/testsuite/gfortran.dg/pr69514_1.f90
branches/gcc-5-branch/gcc/testsuite/gfortran.dg/pr69514_2.f90
Modified:
branches/gcc-5-branch/gcc/fortran/ChangeLog
branches/gcc-5-branch/gcc/fortran/array.c
branches/gcc-5-branch/gcc/testsuite/ChangeLog