Bug 23172 - [4.1/4.2 Regression] ICE on integer initialization, GNU extension
Summary: [4.1/4.2 Regression] ICE on integer initialization, GNU extension
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Giovanni Bajo
URL:
Keywords: ice-on-valid-code, monitored
Depends on:
Blocks:
 
Reported: 2005-08-01 11:03 UTC by Volker Reichelt
Modified: 2005-12-27 17:19 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-11-29 15:49:09


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2005-08-01 11:03:12 UTC
The following code snippet causes an ICE (segfault) on mainline when
compiled with the C++ frontend:

=====================
int i = (int){0};
=====================

This might be related to PR 23171.
Comment 1 Andrew Pinski 2005-08-01 11:55:46 UTC
Confirmed, this is one is a front-end bug.
Comment 2 James A. Morrison 2005-08-20 20:38:01 UTC
int i = (int){1, 2} segfaults as well, and no longer gives an error.

 I suspect it was the following patch:
2005-07-20  Giovanni Bajo  <giovannibajo@libero.it>

        Make CONSTRUCTOR use VEC to store initializers.
        ...
        (digest_init): Rewrite.
        ...
Comment 3 Andrew Pinski 2005-08-20 21:09:44 UTC
Hmm, this is not even valid C99, and we reject it in the C front-end with "-std=c99 -pedantic-errors":
t.c:1: error: initializer element is not constant


Though we should not seg fault.
Comment 4 Andrew Pinski 2005-08-20 21:27:35 UTC
_Complex double i = (_Complex double){0.,1.0};
Also ICE but with a differnet error message:
t.cc:1: internal compiler error: in process_init_constructor, at cp/typeck2.c:1041
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Complex should be handled the same as a scalar.
Comment 5 Andrew Pinski 2005-08-20 21:29:21 UTC
I have a fix for this (really I am writting a fix).
Comment 6 Andrew Pinski 2005-08-20 21:47:23 UTC
Another testcase:
int *f = &(int){0};

This one is valid C99 also.
Comment 7 Andrew Pinski 2005-08-20 21:51:44 UTC
I am going to punt as the last example did not work in 2.95.3-4.0.0 also and that is the only example 
in this whole bug which is really valid C99.
Comment 8 Mark Mitchell 2005-10-31 04:31:37 UTC
Leaving as P2.
Comment 9 Steven Bosscher 2005-12-18 16:36:41 UTC
Giovanni, you never assigned this bug to yourself as far as I can tell, but could you give this bug a quick look anyway, or otherwise unassign yourself from this bug? Thanks.
Comment 10 Mark Mitchell 2005-12-27 06:09:21 UTC
Subject: Bug 23172

Author: mmitchel
Date: Tue Dec 27 06:09:13 2005
New Revision: 109075

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109075
Log:
	PR c++/23171, c++/23172, c++/25417.
	* c-decl.c (compound_literal_number): Remove.
	(build_compound_literal): Use set_compound_literal_name.
	* c-common.c (compound_literal_number): New variable.
	(set_compound_literal_name): New function.
	* c-common.h (set_compound_literal_name): Declare.

	PR c++/23171, c++/23172, c++/25417.
	* typeck.c (build_unary_op): Create temporary variables for
	compound literals whose addresses are taken.
	* init.c (expand_aggr_init_1): Use COMPOUND_LITERAL_P.
	* decl.c (reshape_init_vector): Likewise.
	(reshape_init): Give it external linkage.
	(check_initializer): Use COMPOUND_LITERAL_P.
	(initialize_artificial_var): Allow the initializer to be a
	CONSTRUCTOR.
	* call.c (make_temporary_var_for_ref_to_temp): Use
	create_temporary_var.
	* cp-tree.h (COMPOUND_LITERAL_P): New macro.
	(rehape_init): Declare.
	* typeck2.c (digest_init): Use COMPOUND_LITERAL_P.
	* semantics.c (finish_compound_literal): Use reshape_init.

	PR c++/23172
	* g++.dg/ext/complit4.C: New test.

	PR c++/25417
	* g++.dg/ext/complit5.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/ext/complit4.C
    trunk/gcc/testsuite/g++.dg/ext/complit5.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/c-common.h
    trunk/gcc/c-decl.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/init.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/cp/typeck2.c
    trunk/gcc/testsuite/ChangeLog

Comment 11 Mark Mitchell 2005-12-27 17:18:12 UTC
Subject: Bug 23172

Author: mmitchel
Date: Tue Dec 27 17:18:05 2005
New Revision: 109081

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109081
Log:
	PR c++/23171, c++/23172, c++/25417.
	* c-decl.c (compound_literal_number): Remove.
	(build_compound_literal): Use set_compound_literal_name.
	* c-common.c (compound_literal_number): New variable.
	(set_compound_literal_name): New function.
	* c-common.h (set_compound_literal_name): Declare.
	
2005-12-26  Mark Mitchell  <mark@codesourcery.com>

	PR c++/23171, c++/23172, c++/25417.
	* typeck.c (build_unary_op): Create temporary variables for
	compound literals whose addresses are taken.
	* init.c (expand_aggr_init_1): Use COMPOUND_LITERAL_P.
	* decl.c (reshape_init_vector): Likewise.
	(reshape_init): Give it external linkage.
	(check_initializer): Use COMPOUND_LITERAL_P.
	(initialize_artificial_var): Allow the initializer to be a
	CONSTRUCTOR.
	* call.c (make_temporary_var_for_ref_to_temp): Use
	create_temporary_var.
	* cp-tree.h (COMPOUND_LITERAL_P): New macro.
	(rehape_init): Declare.
	* typeck2.c (digest_init): Use COMPOUND_LITERAL_P.
	* semantics.c (finish_compound_literal): Use reshape_init.

2005-12-26  Mark Mitchell  <mark@codesourcery.com>

	PR c++/23172
	* g++.dg/ext/complit4.C: New test.

	PR c++/25417
	* g++.dg/ext/complit5.C: Likewise.


Added:
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/ext/complit4.C
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/ext/complit5.C
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/c-common.c
    branches/gcc-4_1-branch/gcc/c-common.h
    branches/gcc-4_1-branch/gcc/c-decl.c
    branches/gcc-4_1-branch/gcc/cp/ChangeLog
    branches/gcc-4_1-branch/gcc/cp/call.c
    branches/gcc-4_1-branch/gcc/cp/cp-tree.h
    branches/gcc-4_1-branch/gcc/cp/decl.c
    branches/gcc-4_1-branch/gcc/cp/init.c
    branches/gcc-4_1-branch/gcc/cp/semantics.c
    branches/gcc-4_1-branch/gcc/cp/typeck.c
    branches/gcc-4_1-branch/gcc/cp/typeck2.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 12 Mark Mitchell 2005-12-27 17:19:22 UTC
Fixed in 4.1.