I am not sure that the example is valid GCC-extended C, but GCC definitely should not ICE with "gimplification failed". The example is: typedef short __attribute__((vector_size (16))) v8hi; union vx {short f[8]; v8hi v;}; extern void bar1(v8hi); void foo5 (v8hi vec, short n) { ((union vx) vec).f[5] = n; bar1 (foo.v); } This is either ice-on-valid or ice-on-invalid, but something is broken.
The front-end produces: {.v=vec}.f[5] = n;
Sorry, there was a typo in the previous example. The correct example is: typedef short __attribute__((vector_size (16))) v8hi; union vx {short f[8]; v8hi v;}; extern void bar1(v8hi); void foo5 (v8hi vec, short n) { ((union vx) vec).f[5] = n; bar1 (vec); } and the output is: $ ./xgcc -B./ -O0 -S a.c gimplification failed: {.v=vec} <constructor 0x426c1c00 type <union_type 0x426ba770 vx type_0 BLK size <integer_cst 0x42611a60 constant invariant 128> unit size <integer_cst 0x42611a80 constant invariant 16> align 128 symtab 0 alias set -1 fields <field_decl 0x426ba8c0 f type <array_type 0x42694d20> BLK file a.c line 2 size <integer_cst 0x42611a60 128> unit size <integer_cst 0x42611a80 16> align 16 offset_align 128 offset <integer_cst 0x42611400 constant invariant 0> bit offset <integer_cst 0x42611e80 constant invariant 0> context <union_type 0x426ba770 vx> chain <field_decl 0x426ba930 v>> chain <type_decl 0x42620a00 D.1265>> arg 0 <tree_list 0x426c1be0 purpose <field_decl 0x426ba930 v type <vector_type 0x426ba700 v8hi> TI file a.c line 2 size <integer_cst 0x42611a60 128> unit size <integer_cst 0x42611a80 16> align 128 offset_align 128 offset <integer_cst 0x42611400 0> bit offset <integer_cst 0x42611e80 0> context <union_type 0x426ba770 vx>> value <parm_decl 0x426baa80 vec type <vector_type 0x426ba700 v8hi> used TI file a.c line 7 size <integer_cst 0x42611a60 128> unit size <integer_cst 0x42611a80 16> align 128 context <function_decl 0x426bb800 foo5> initial <vector_type 0x426ba700 v8hi> arg-type <vector_type 0x426ba700 v8hi> chain <parm_decl 0x426baaf0 n>>>> a.c: In function 'foo5': a.c:9: internal compiler error: gimplification failed
Here is another testcase: union vx {short f[8]; int v;}; int vec; void foo5 (int vec) { ((union vx) vec).f[5] = 1; }
If we give -pedantic-errors we reject it with an error but still ICE.
It's an lvalue-cast, which we no longer support as an extension. So it's ICE on invalid and a frontend bug. The C++ frontend spits out the interesting error pr23155.c: In function ‘void foo5(int)’: pr23155.c:7: error: no matching function for call to ‘vx::vx(int&)‘ pr23155.c:1: note: candidates are: vx::vx() pr23155.c:1: note: vx::vx(const vx&) The following get's rejected with what should be done with the original testcase, too: union vx {short f[8]; int v;}; int vec; void bar(short *); void foo5 (int vec) { bar(((union vx) vec).f); } pr23155.c: In function ‘foo5’: pr23155.c:10: error: invalid use of non-lvalue array
: Search converges between 2004-06-20-trunk (#469) and 2004-06-22-trunk (#470). Hmm, this was not introduced by the tree-ssa merge weird.
The testcase from comment #5 ICEs starting with this patch from kenner: http://gcc.gnu.org/ml/gcc-cvs/2004-06/msg00881.html
I might look into this soon.
This is a combination of a GCC extension (of cast to union) and a C99 feature (subscripting a non-lvalue array) so this is valid code (but undefined code) even though it looks so weird. Anyways I have a patch which I am testing.
Patch posted: <http://gcc.gnu.org/ml/gcc-patches/2005-10/msg01598.html>.
Leaving as P2.
Subject: Bug 23155 Author: pinskia Date: Thu Nov 3 16:15:53 2005 New Revision: 106438 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106438 Log: 2005-11-03 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/23155 * g++.dg/ext/c99struct1.C: New test. * gcc.dg/union-cast-1.c: New test. * gcc.dg/union-cast-2.c: New test. * gcc.dg/union-cast-3.c: New test. 2005-11-03 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/23155 * gimplifier.c (gimplify_expr): Create a temporary for lvalue CONSTRUCTOR. Added: trunk/gcc/testsuite/g++.dg/ext/c99struct1.C trunk/gcc/testsuite/gcc.dg/union-cast-1.c trunk/gcc/testsuite/gcc.dg/union-cast-2.c trunk/gcc/testsuite/gcc.dg/union-cast-3.c Modified: trunk/gcc/ChangeLog trunk/gcc/gimplify.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 23155 Author: pinskia Date: Thu Nov 3 16:21:52 2005 New Revision: 106439 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106439 Log: 2005-11-03 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/23155 * g++.dg/ext/c99struct1.C: New test. * gcc.dg/union-cast-1.c: New test. * gcc.dg/union-cast-2.c: New test. * gcc.dg/union-cast-3.c: New test. 2005-11-03 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/23155 * gimplifier.c (gimplify_expr): Create a temporary for lvalue CONSTRUCTOR. Added: branches/gcc-4_0-branch/gcc/testsuite/g++.dg/ext/c99struct1.C - copied unchanged from r106438, trunk/gcc/testsuite/g++.dg/ext/c99struct1.C branches/gcc-4_0-branch/gcc/testsuite/gcc.dg/union-cast-1.c - copied unchanged from r106438, trunk/gcc/testsuite/gcc.dg/union-cast-1.c branches/gcc-4_0-branch/gcc/testsuite/gcc.dg/union-cast-2.c - copied unchanged from r106438, trunk/gcc/testsuite/gcc.dg/union-cast-2.c branches/gcc-4_0-branch/gcc/testsuite/gcc.dg/union-cast-3.c - copied unchanged from r106438, trunk/gcc/testsuite/gcc.dg/union-cast-3.c Modified: branches/gcc-4_0-branch/gcc/ChangeLog branches/gcc-4_0-branch/gcc/gimplify.c branches/gcc-4_0-branch/gcc/testsuite/ChangeLog
Fixed.