Bug 16819 - [3.4 regression] ICE with empty struct as arg
Summary: [3.4 regression] ICE with empty struct as arg
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.0.0
: P3 normal
Target Milestone: 3.4.4
Assignee: Alexandre Oliva
URL:
Keywords: ice-on-valid-code, monitored, patch
Depends on:
Blocks:
 
Reported: 2004-07-29 12:32 UTC by Christian Lindig
Modified: 2004-12-23 23:09 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.3.4 3.3.3 3.3.1 3.0.4 4.0.0
Known to fail: 3.4.1
Last reconfirmed: 2004-12-08 18:14:37


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Lindig 2004-07-29 12:32:10 UTC
Compilic the code below with -O3 results in an internal compiler
error. The error is most likely corellated with empty structs
and and non-static functions. If functions are declared static
it does not occur, also it only occurs with empty structs passed by
value..

The code was generated with my test-code generator Quest:
http://www.st.cs.uni-sb.de/~lindig/src/quest/index.html

foo.c: In function `main':
foo.c:124: error: unable to find a register to spill in class `AREG'
foo.c:124: error: this is the insn:
(jump_insn:HI 32 170 37 0 (parallel [
            (set (pc)
                (if_then_else (eq (reg:DF 9 st(1) [orig:79 x002vg.x002vd ] [79])
                        (reg:DF 8 st [orig:80 x002pc ] [80]))
                    (label_ref 46)
                    (pc)))
            (clobber (reg:CCFP 18 fpsr))
            (clobber (reg:CCFP 17 flags))
            (clobber (scratch:HI))
        ]) 355 {*fp_jcc_5} (insn_list 30 (insn_list 31 (nil)))
    (expr_list:REG_UNUSED (scratch:HI)
        (expr_list:REG_UNUSED (reg:CCFP 17 flags)
            (expr_list:REG_UNUSED (reg:CCFP 18 fpsr)
                (expr_list:REG_DEAD (reg:DF 9 st(1) [orig:79 x002vg.x002vd ] [79])
                    (expr_list:REG_DEAD (reg:DF 8 st [orig:80 x002pc ] [80])
                        (expr_list:REG_UNUSED (scratch:HI)
                            (expr_list:REG_UNUSED (reg:CCFP 17 flags)
                                (expr_list:REG_UNUSED (reg:CCFP 18 fpsr)
                                    (expr_list:REG_BR_PROB (const_int 7000 [0x1b58])
                                        (nil)))))))))))
foo.c:124: internal compiler error: in spill_failure, at reload1.c:1887
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Environment:
System: Linux jacobs 2.4.26-1-686 #1 Sat May 1 18:04:05 EST 2004 i686 GNU/Linux
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-snapshot/configure --enable-languages=c --prefix=/tmp/lindig/gcc

How-To-Repeat:

    gcc -O3 foo.c
    

# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "foo.c"





extern int printf (char *, ...);

static int errors = 0;

static void failed( int line )
{ printf ("failed in %s: %d\n", "foo.c", line); errors++; }

static struct x002tf { } x002vj = { };

static struct x002te { } x002ve = { };

static unsigned int *x002vf = (unsigned int *) 936956372U;

static union x002td { double x002vd[1]; } x002vg = { { 88192.222629 } };

static
struct x002tc
{
    double (**x002vc)[1];
    union x002tb { } x002vb;
    struct x002ta { } *x002va;
}
x002vh
=
    { (double (**)[1]) 221053595U, { }, (struct x002ta *) 215342829U };

static unsigned short int *x002vi = (unsigned short int *) 1191863793U;

struct x002tf
x002fa(
    struct x002te x002pa,
    unsigned int *x002pb,
    union x002td x002pc,
    struct x002tc x002pd,
    unsigned short int *x002pe
)
{
    if (x002vf != x002pb) failed (43);
    if (x002vg.x002vd[0] != x002pc.x002vd[0]) failed (44);
    if (x002vh.x002vc != x002pd.x002vc) failed (45);
    if (x002vh.x002va != x002pd.x002va) failed (46);
    if (x002vi != x002pe) failed (47);
    return x002vj;
}

static void x002fb( )
{
    struct x002tf x002vk;
    x002vk = x002fa (x002ve, x002vf, x002vg, x002vh, x002vi);
}

static struct x001th { } **x001vr = (struct x001th **) 282125612U;

static
union x001tg
{
    unsigned char x001vm;
    struct x001tf { char x001vk; float x001vj; } *x001vl;
    union x001te { unsigned char x001vh; struct x001td { } x001vg; } *x001vi;
}
x001vn
=
    { '\x77' };

static
struct x001tc
{ unsigned char x001vf; char **x001ve; unsigned int x001vd[2]; }
x001vo[2]
=
    {
        { '\x4f', (char **) 447267482U, { 17134777U, 449880647U } },
        { '\x3', (char **) 1576399922U, { 1846818777U, 928825020U } }
    };

static
struct x001tb
{ unsigned int *x001vc; unsigned char x001vb; double x001va[2][1]; }
x001vp
=
    {
        (unsigned int *) 2102563535U,
        '\x8',
        { { 36299.571769 }, { 62135.529636 } }
    };

static union x001ta { } x001vq = { };

struct x001th **
x001fa(
    union x001tg x001pa,
    struct x001tc x001pb[2],
    struct x001tb x001pc,
    union x001ta x001pd
)
{
    if (x001vn.x001vm != x001pa.x001vm) failed (101);
    if (x001vo[1].x001vf != x001pb[1].x001vf) failed (102);
    if (x001vo[0].x001vf != x001pb[0].x001vf) failed (103);
    if (x001vo[1].x001ve != x001pb[1].x001ve) failed (104);
    if (x001vo[0].x001ve != x001pb[0].x001ve) failed (105);
    if (x001vo[1].x001vd[1] != x001pb[1].x001vd[1]) failed (106);
    if (x001vo[1].x001vd[0] != x001pb[1].x001vd[0]) failed (107);
    if (x001vo[0].x001vd[1] != x001pb[0].x001vd[1]) failed (108);
    if (x001vo[0].x001vd[0] != x001pb[0].x001vd[0]) failed (109);
    if (x001vp.x001vc != x001pc.x001vc) failed (110);
    if (x001vp.x001vb != x001pc.x001vb) failed (111);
    if (x001vp.x001va[1][0] != x001pc.x001va[1][0]) failed (112);
    if (x001vp.x001va[0][0] != x001pc.x001va[0][0]) failed (113);
    return x001vr;
}

static void x001fb( )
{
    struct x001th **x001vs;
    x001vs = x001fa (x001vn, x001vo, x001vp, x001vq);
    if (x001vr != x001vs) failed (121);
}

int main( int argc, char **argv ) { x002fb (); x001fb (); return errors; }
Comment 1 Wolfgang Bangerth 2004-07-29 13:21:20 UTC
Confirmed. A regression in 3.4 and mainline against 3.3.4. 
 
W. 
Comment 2 Wolfgang Bangerth 2004-07-29 13:37:19 UTC
Here's something likely smaller: 
------------------------ 
extern int printf (char *, ...); 
int errors = 0; 
 
void failed() 
{ printf (""); errors++; } 
 
union ytd { double yvd[1]; } yvg; 
 
union xtg 
{ unsigned char xvm; } xvn; 
 
struct xtc 
{ unsigned char xvf; unsigned int xvd[2]; } xvo[2]; 
 
struct xtb 
{ unsigned int *xvc; unsigned char xvb; double xva[2][1]; } xvp; 
 
union xta { } xvq; 
 
void yfa(union ytd ypc) 
{ if (yvg.yvd[0] != ypc.yvd[0]) failed (); } 
 
void xfa(union xtg xpa, 
            struct xtc xpb[2], 
            struct xtb xpc, 
            union xta xpd) { 
  if (xvn.xvm != xpa.xvm)             failed (); 
  if (xvo[1].xvf != xpb[1].xvf)       failed (); 
  if (xvo[0].xvd[0] != xpb[0].xvd[0]) failed (); 
  if (xvp.xvc != xpc.xvc)             failed (); 
  if (xvp.xvb != xpc.xvb)             failed (); 
  if (xvp.xva[1][0] != xpc.xva[1][0]) failed (); 
  if (xvp.xva[0][0] != xpc.xva[0][0]) failed (); 
} 
 
int main() { 
  yfa (yvg); 
  xfa (xvn, xvo, xvp, xvq); 
} 
------------------------------ 
 
g/x> /home/bangerth/bin/gcc-3.5-pre/bin/gcc -O3 -c x.c 
x.c: In function `main': 
x.c:39: error: unable to find a register to spill in class `AREG' 
x.c:39: error: this is the insn: 
(insn:HI 74 85 75 0 (set (reg:HI 1 dx [94]) 
        (unspec:HI [ 
                (compare:CCFPU (reg:DF 9 st(1) [orig:72 yvg.yvd ] [72]) 
                    (reg:DF 8 st [orig:73 ypc ] [73])) 
            ] 24)) 21 {*cmpfp_2u_1} (nil) 
    (expr_list:REG_DEAD (reg:DF 9 st(1) [orig:72 yvg.yvd ] [72]) 
        (expr_list:REG_DEAD (reg:DF 8 st [orig:73 ypc ] [73]) 
            (nil)))) 
x.c:39: internal compiler error: in spill_failure, at reload1.c:1887 
Please submit a full bug report, 
with preprocessed source if appropriate. 
See <URL:http://gcc.gnu.org/bugs.html> for instructions. 
 
While the ICE happens in the same place in reload1 all the time, the exact 
insn that fails is different. If someone fixes this PR, please also check 
the original testcase. 
 
W. 
Comment 3 Andrew Pinski 2004-07-29 14:32:08 UTC
: Search converges between 2003-03-03-trunk (#198) and 2003-03-04-trunk (#199).
Comment 4 Volker Reichelt 2004-08-02 22:40:47 UTC
Here's a further reduced code snippet:

=========================
double d=0;

struct A {} a;

void foo(struct A x)
{
  d=0;
}

void bar()
{
  if (d) foo(a);
}
=========================

This thing crashes at -O since gcc 2.95.x, so this is not really a regression.
Making foo static does not help. But the struct being empty seems to be
essential.
Comment 5 Mark Mitchell 2004-11-01 00:46:36 UTC
Postponed until GCC 3.4.4.
Comment 6 Andrew Pinski 2004-12-22 16:34:20 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-12/msg01712.html>.
Comment 7 GCC Commits 2004-12-23 16:09:16 UTC
Subject: Bug 16819

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	aoliva@gcc.gnu.org	2004-12-23 16:09:01

Modified files:
	gcc            : ChangeLog calls.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: empty2.c 

Log message:
	gcc/ChangeLog:
	PR target/16819
	* calls.c (load_register_parameters): Don't call use_regs when
	nregs is zero.
	gcc/testsuite/ChangeLog:
	PR target/16891
	* gcc.dg/empty2.c: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6943&r2=2.6944
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/calls.c.diff?cvsroot=gcc&r1=1.373&r2=1.374
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4803&r2=1.4804
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/empty2.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 Andrew Pinski 2004-12-23 16:25:55 UTC
Fixed at least on the mainline.
Comment 9 GCC Commits 2004-12-23 21:39:15 UTC
Subject: Bug 16819

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	aoliva@gcc.gnu.org	2004-12-23 21:39:04

Modified files:
	gcc            : ChangeLog calls.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: empty2.c 

Log message:
	gcc/ChangeLog:
	PR target/16819
	* calls.c (load_register_parameters): Don't call use_regs when
	nregs is zero.
	gcc/testsuite/ChangeLog:
	PR target/16819
	* gcc.dg/empty2.c: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.751&r2=2.2326.2.752
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/calls.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.315.2.6&r2=1.315.2.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.336&r2=1.3389.2.337
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/empty2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.2.2.1

Comment 10 Andrew Pinski 2004-12-23 23:09:33 UTC
Fixed.