Bug 40018 - [4.4/4.5 Regression] ICE in output_constructor
Summary: [4.4/4.5 Regression] ICE in output_constructor
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P4 normal
Target Milestone: 4.4.1
Assignee: Paul Thomas
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2009-05-04 19:01 UTC by Francois-Xavier Coudert
Modified: 2009-05-10 16:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.3
Known to fail:
Last reconfirmed: 2009-05-06 20:46:37


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2009-05-04 19:01:03 UTC
$ cat a.f90 
  integer(kind=8) :: i
  write(*,*) [(i, i = 1, 10)]
  end

$ gfortran a.f90
a.f90:2: internal compiler error: in output_constructor, at varasm.c:4712

The GDB backtrace is:

#0  fancy_abort (file=0xd7999a "../../trunk/gcc/varasm.c", line=4716, 
    function=0xd792d0 "output_constructor") at ../../trunk/gcc/diagnostic.c:723
#1  0x000000000094b762 in output_constructor (exp=<value optimized out>, 
    size=<value optimized out>, align=<value optimized out>)
    at ../../trunk/gcc/varasm.c:4716
#2  0x00000000009bec65 in varpool_assemble_decl (node=0x2ace99df7a40)
    at ../../trunk/gcc/varpool.c:364
#3  0x000000000098f991 in cgraph_output_in_order ()
    at ../../trunk/gcc/cgraphunit.c:1202
#4  0x0000000000991622 in cgraph_optimize ()
    at ../../trunk/gcc/cgraphunit.c:1318
#5  0x00000000005125e5 in gfc_be_parse_file (set_yydebug=<value optimized out>)
    at ../../trunk/gcc/fortran/f95-lang.c:237
#6  0x00000000007e0324 in toplev_main (argc=2, argv=0x7fff143ae1b8)
    at ../../trunk/gcc/toplev.c:977

Happens on x86_64-linux with current trunk (rev. 147105), and i686-apple-darwin9 rev. 144983.
Comment 1 Dominique d'Humieres 2009-05-04 19:19:24 UTC
Confirmed on trunk and 4.4.0. Works with 4.3.3.
Comment 2 Tobias Burnus 2009-05-05 09:07:29 UTC
Mark as regression based on Dominique's comment.
Comment 3 Richard Biener 2009-05-05 09:58:56 UTC
Confirmed.

#1  0x0000000000befdf6 in output_constructor (exp=0x7ffff7fd0cc0, size=80, 
    align=256) at /space/rguenther/src/svn/trunk/gcc/varasm.c:4716
4716                  gcc_assert (pos >= total_bytes);
(gdb) p pos
$1 = 4
(gdb) p total_bytes
$2 = 8
(gdb) call debug_generic_expr (exp)
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

(gdb) call debug_tree (exp)
 <constructor 0x7ffff7fd0cc0
    type <array_type 0x7ffff5f3c0c0
        type <integer_type 0x7ffff7ee16c0 integer(kind=8) public DI
...
    idx <integer_cst 0x7ffff7eedae0 type <integer_type 0x7ffff7ee16c0 integer(kind=8)> constant 0>
    val <integer_cst 0x7ffff7eed090 type <integer_type 0x7ffff7ee1540 integer(kind=4)> constant 1>
...

there is a mismatch with the array element type and the actual element
types.  Thus confirmed as a frontend issue.
Comment 4 Paul Thomas 2009-05-06 20:46:34 UTC
This fixes it and is regtesting right now.

Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c	(revision 147128)
+++ gcc/fortran/trans-array.c	(working copy)
@@ -1620,6 +1620,7 @@
     {
       gfc_init_se (&se, NULL);
       gfc_conv_constant (&se, c->expr);
+      se.expr = fold_convert (type, se.expr);
       if (c->expr->ts.type == BT_CHARACTER && POINTER_TYPE_P (type))
 	se.expr = gfc_build_addr_expr (gfc_get_pchar_type (c->expr->ts.kind),
 				       se.expr);

I am looking to see if this cannot be done in the front-end.

Note the enormous difference in the code produced in 4.3, compared with 4.4 and trunk.  Fixing assignments exposed this little gem!

Paul
Comment 5 Dominique d'Humieres 2009-05-06 21:43:40 UTC
The patch in comment #4 fixes this pr, but gives:

.*: internal compiler error: in fold_convert, at fold-const.c:2551

in 83 of my tests, for instance

[ibook-dhum] f90/bug% cat pr36257.f90
  implicit none
  character(len=5), dimension(3,3), parameter :: &
    p = reshape(["", "", "", "", "", "", "", "", ""], [3,3])
  character(len=5), dimension(3,3) :: m1

  m1 = p
  if (any (spread (p, 1, 2) /= spread (m1, 1, 2))) call abort

end

I did not review all the cases, but all those I have looked at deal with constructor+strings.
Comment 6 Paul Thomas 2009-05-07 04:44:39 UTC
(In reply to comment #5)
> The patch in comment #4 fixes this pr, but gives:
> 
> .*: internal compiler error: in fold_convert, at fold-const.c:2551

Yes... I went to bed when the regression test started spewing out the errors.  The fix is easy... I think :-)  The type must be checked for not being a character type before doing the fold_convert.

It's regtesting right now.

Cheers

Paul
Comment 7 Paul Thomas 2009-05-10 10:21:21 UTC
Subject: Bug 40018

Author: pault
Date: Sun May 10 10:21:08 2009
New Revision: 147331

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147331
Log:
2009-05-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/40018
	* trans-array.c (gfc_trans_array_constructor_value): Fold
	convert numeric constants.
	(gfc_build_constant_array_constructor): The same.

2009-05-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/40018
	* gfortran.dg/array_constructor_31.f90: New test.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/testsuite/ChangeLog

Comment 8 Paul Thomas 2009-05-10 10:22:49 UTC
Subject: Bug 40018

Author: pault
Date: Sun May 10 10:22:37 2009
New Revision: 147332

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147332
Log:
2009-05-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/40018
	* trans-array.c (gfc_trans_array_constructor_value): Fold
	convert numeric constants.
	(gfc_build_constant_array_constructor): The same.

2009-05-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/40018
	* gfortran.dg/array_constructor_31.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/array_constructor_31.f90

Comment 9 Paul Thomas 2009-05-10 16:14:53 UTC
Subject: Bug 40018

Author: pault
Date: Sun May 10 16:14:37 2009
New Revision: 147347

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147347
Log:
2009-05-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/40018
	* trans-array.c (gfc_trans_array_constructor_value): Fold
	convert numeric constants.
	(gfc_build_constant_array_constructor): The same.

2009-05-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/40018
	* gfortran.dg/array_constructor_31.f90: New test.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/array_constructor_31.f90
Modified:
    branches/gcc-4_4-branch/gcc/fortran/ChangeLog
    branches/gcc-4_4-branch/gcc/fortran/trans-array.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog

Comment 10 Paul Thomas 2009-05-10 16:15:52 UTC
Fixed on trunk and 4.4

Thanks for the report

Paul