Bug 23155 - [4.0/4.1 Regression] Gimplification failed for union cast
Summary: [4.0/4.1 Regression] Gimplification failed for union cast
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.0.3
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: error-recovery, ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2005-07-31 04:18 UTC by David Edelsohn
Modified: 2005-11-03 16:22 UTC (History)
3 users (show)

See Also:
Host: *-*-*
Target: *-*-*
Build: *-*-*
Known to work:
Known to fail:
Last reconfirmed: 2005-07-31 04:21:21


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Edelsohn 2005-07-31 04:18:12 UTC
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.
Comment 1 Andrew Pinski 2005-07-31 04:21:21 UTC
The front-end produces:
  {.v=vec}.f[5] = n;
Comment 2 David Edelsohn 2005-07-31 04:21:51 UTC
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
Comment 3 Andrew Pinski 2005-07-31 04:23:44 UTC
Here is another testcase:
union vx {short f[8]; int v;};
int vec;

void
foo5 (int vec)
{
  ((union vx) vec).f[5] = 1;
}
Comment 4 Andrew Pinski 2005-07-31 04:25:01 UTC
If we give -pedantic-errors we reject it with an error but still ICE.
Comment 5 Richard Biener 2005-08-04 09:20:49 UTC
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
Comment 6 Andrew Pinski 2005-08-08 18:26:35 UTC
: 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.
Comment 7 Janis Johnson 2005-09-16 20:22:35 UTC
The testcase from comment #5 ICEs starting with this patch from kenner:

  http://gcc.gnu.org/ml/gcc-cvs/2004-06/msg00881.html
Comment 8 Andrew Pinski 2005-10-27 20:01:43 UTC
I might look into this soon.
Comment 9 Andrew Pinski 2005-10-27 21:15:11 UTC
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.
Comment 10 Andrew Pinski 2005-10-28 03:36:24 UTC
Patch posted:
<http://gcc.gnu.org/ml/gcc-patches/2005-10/msg01598.html>.
Comment 11 Mark Mitchell 2005-10-31 04:29:51 UTC
Leaving as P2.
Comment 12 Andrew Pinski 2005-11-03 16:16:00 UTC
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

Comment 13 Andrew Pinski 2005-11-03 16:21:58 UTC
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

Comment 14 Andrew Pinski 2005-11-03 16:22:21 UTC
Fixed.