Bug 25309 - [4.1 Regression] ICE on initialization of a huge array
Summary: [4.1 Regression] ICE on initialization of a huge array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.4
: P2 normal
Target Milestone: 4.2.3
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2005-12-08 12:57 UTC by Jens Teubner
Modified: 2008-07-04 15:12 UTC (History)
4 users (show)

See Also:
Host:
Target: i686-pc-linux-gnu, cris-axis-elf
Build:
Known to work: 3.0.4 4.2.3 4.3.0
Known to fail: 3.3.3 3.2.3 3.4.0 4.0.0 4.1.0 4.1.3 4.2.0
Last reconfirmed: 2007-09-26 00:22:34


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Teubner 2005-12-08 12:57:50 UTC
GCC throws an internal compiler error when compiling the following
C99 code (gcc -std=c99 -c):

    static char * name[] = {
        [0x80000000]  = "bar"
    };

(GCC reports `internal compiler error: in tree_low_cst, at tree.c:3318'.)

I realize that the above code is quite stupid, as I request the compiler
to create an array of huge size.  However, I think GCC should not throw
an internal compiler error.  For smaller values of the array index, GCC
correctly reports `error: size of variable 'name' is too large'.

I have reproduced the problem with GCC 3.4.4 (Gentoo Linux) and GCC
3.3.5 (SuSE 9.3), both on Intel Pentium M.
Comment 1 Andrew Pinski 2005-12-08 15:54:05 UTC
Confirmed.  This is only reproducible on targets where HOST_WIDE_INT is 32bits (and I still say that HOST_WIDE_INT should be always at least 64bits).  Oh and this is a regression for at least x86.
Comment 2 Richard Biener 2005-12-08 16:55:53 UTC
HOST_WIDE_INT is what it says.  The code should check host_integerp first and
then use TREE_INT_CST_LOW.
Comment 3 Andrew Pinski 2005-12-12 02:50:21 UTC
: Search converges between 2002-02-17-trunk (#59) and 2002-02-24-trunk (#60).
Comment 4 Andrew Pinski 2005-12-12 02:55:31 UTC
Hmm, I almost want to say this was caused by:
2002-02-20  Roger Sayle  <roger@eyesopen.com>
            Jakub Jelinek  <jakub@redhat.com>

        PR c/4389
        * tree.c (host_integerp): Ensure that the constant integer is
        representable in a HOST_WIDE_INT or an unsigned HOST_WIDE_INT
        when pos is zero or nonzero respectively.  Clarify comment.
        * c-format.c (check_format_info_recurse): Fix host_integerp
        usage; the pos argument should be zero when assigning to a
        signed HOST_WIDE_INT.

Which means it was a latent bug as this added the ICE in the first place.
Comment 5 Mark Mitchell 2005-12-19 19:16:11 UTC
ICE on somewhat odd code: P2.
Comment 6 Mark Mitchell 2006-02-24 00:26:36 UTC
This issue will not be resolved in GCC 4.1.0; retargeted at GCC 4.1.1.
Comment 7 Roger Sayle 2006-04-28 20:00:03 UTC
Subject: Bug 25309

Author: sayle
Date: Fri Apr 28 19:59:57 2006
New Revision: 113355

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113355
Log:

	PR c/25309
	* c-typeck.c (struct spelling): Make I an unsigned HOST_WIDE_INT.
	(push_array_bounds): Delete prototype.  Change BOUNDS argument to
	an unsigned HOST_WIDE_INT.
	(print_spelling): Use HOST_WIDE_INT_PRINT_UNSIGNED to output the
	array index.
	(really_start_incremental_init): No need to call convert because
	bitsize_zero_node is already of type bitsizetype.
	(push_init_level): Extract the value of constructor_index as an
	unsigned HOST_WIDE_INT quantity, using tree_low_cst.
	(process_init_element): Likewise.

	* gcc.dg/large-size-array-2.c: New test case.


Added:
    trunk/gcc/testsuite/gcc.dg/large-size-array-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-typeck.c
    trunk/gcc/testsuite/ChangeLog

Comment 8 Roger Sayle 2006-05-02 17:15:35 UTC
Subject: Bug 25309

Author: sayle
Date: Tue May  2 17:15:25 2006
New Revision: 113476

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113476
Log:

	PR c/25309
	* c-typeck.c (struct spelling): Make I an unsigned HOST_WIDE_INT.
	(push_array_bounds): Delete prototype.  Change BOUNDS argument to
	an unsigned HOST_WIDE_INT.
	(print_spelling): Use HOST_WIDE_INT_PRINT_UNSIGNED to output the
	array index.
	(really_start_incremental_init): No need to call convert because
	bitsize_zero_node is already of type bitsizetype.
	(push_init_level): Extract the value of constructor_index as an
	unsigned HOST_WIDE_INT quantity, using tree_low_cst.
	(process_init_element): Likewise.

	* gcc.dg/large-size-array-2.c: New test case.


Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/large-size-array-2.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/c-typeck.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 9 Roger Sayle 2006-05-03 18:49:53 UTC
Subject: Bug 25309

Author: sayle
Date: Wed May  3 18:49:40 2006
New Revision: 113500

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113500
Log:

	PR c/25309
	* c-typeck.c (struct spelling): Make I an unsigned HOST_WIDE_INT.
	(push_array_bounds): Delete prototype.  Change BOUNDS argument to
	an unsigned HOST_WIDE_INT.
	(print_spelling): Use HOST_WIDE_INT_PRINT_UNSIGNED to output the
	array index.
	(really_start_incremental_init): No need to call convert because
	bitsize_zero_node is already of type bitsizetype.
	(push_init_level): Extract the value of constructor_index as an
	unsigned HOST_WIDE_INT quantity, using tree_low_cst.
	(process_init_element): Likewise.

	* gcc.dg/large-size-array-2.c: New test case.


Added:
    branches/gcc-4_0-branch/gcc/testsuite/gcc.dg/large-size-array-2.c
Modified:
    branches/gcc-4_0-branch/gcc/ChangeLog
    branches/gcc-4_0-branch/gcc/c-typeck.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog

Comment 10 roger 2006-05-04 00:14:36 UTC
This should now be fixed on mainline and all active branches.
Comment 11 Hans-Peter Nilsson 2007-03-18 15:43:30 UTC
I see this error for cris-axis-elf with trunk, as late as r123034:
gcc.dg/large-size-array-2.c:6: internal compiler error: in tree_low_cst, at tree.c:4867
I think the proper action is to re-open the PR, right?
Comment 12 Andrew Pinski 2007-03-18 17:38:13 UTC
Ok, I can reproduce this ICE on a cross to cris-axis-elf, why it works for powerpc-darwin and spu-elf, I don't know.  Does cris normally have HOST_WIDE_INT as being 32bits?
Comment 13 Hans-Peter Nilsson 2007-03-18 23:04:34 UTC
I'm not sure I understand comment #12, because HOST_WIDE_INT is decided by the host, not the target, unless need_64bit_hwint=yes but that's *not* set for cris-*-*; it's a fairly regular 32-bit:er.  I saw this with a cross from a x86_64-unknown-linux-gnu host (64-bit longs).
Comment 14 Joseph S. Myers 2007-09-26 00:22:34 UTC
Working on a patch.
Comment 15 Joseph S. Myers 2007-09-26 12:32:48 UTC
Subject: Bug 25309

Author: jsm28
Date: Wed Sep 26 12:32:27 2007
New Revision: 128811

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128811
Log:
	PR c/25309
	* c-common.c (complete_array_type): Diagnose too-large arrays and
	set type to error_mark_node.

testsuite:
	* gcc.dg/large-size-array-2.c: Expect diagnostic for too-large
	array.
	* gcc.dg/large-size-array-4.c: New.  Copy of large-size-array-2.c
	without -O2.

Added:
    trunk/gcc/testsuite/gcc.dg/large-size-array-4.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/large-size-array-2.c

Comment 16 Joseph S. Myers 2007-09-27 12:19:49 UTC
Fixed for 4.3.0.
Comment 17 Joseph S. Myers 2007-10-10 20:46:22 UTC
Subject: Bug 25309

Author: jsm28
Date: Wed Oct 10 20:46:11 2007
New Revision: 129216

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129216
Log:
	PR c/25309
	* c-common.c (complete_array_type): Diagnose too-large arrays and
	set type to error_mark_node.

testsuite:
	* gcc.dg/large-size-array-2.c: Expect diagnostic for too-large
	array.
	* gcc.dg/large-size-array-4.c: New.  Copy of large-size-array-2.c
	without -O2.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/gcc.dg/large-size-array-4.c
Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/c-common.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_2-branch/gcc/testsuite/gcc.dg/large-size-array-2.c

Comment 18 Joseph S. Myers 2007-10-10 21:19:19 UTC
Fixed for 4.2.3.
Comment 19 Joseph S. Myers 2008-07-04 15:12:05 UTC
Closing 4.1 branch.