The below testcase ICEs in get_constraint_for_component_ref when compiled with -O1 or beyond on x86_64. Richard mentions that it also fails with trunk. --------------------------------------- /* compile with gcc -c -Os -o foo.o foo.c */ typedef struct { struct { } z; } thang_t; struct widget { struct widget *p, *q; }; typedef struct thing { struct widget x; } thing_t; struct { int a; int b; int c; int d; int e; thang_t f; thing_t g; } my_struct; static void foo(thang_t *r) { splat(r);} void function(int blaz) { foo(&my_struct.f);} ---------------------------------------
Confirmed. We access a zero-sized part of the structure: arg 1 <field_decl 0x2a959f2180 f type <record_type 0x2a959dfb00 thang_t> BLK file t.c line 16 size <integer_cst 0x2a958ab750 0> unit size <integer_cst 0x2a95891720 0> align 8 offset_align 128 offset <integer_cst 0x2a958ab0f0 constant invariant 16> bit offset <integer_cst 0x2a95891bd0 constant invariant 32> context <record_type 0x2a959dfe70> chain <field_decl 0x2a959f2240 g type <record_type 0x2a959dfdc0 thing_t> BLK file t.c line 17 size <integer_cst 0x2a958ab0c0 constant invariant 128> unit size <integer_cst 0x2a958ab0f0 16> align 64 offset_align 128 offset <integer_cst 0x2a958ab0f0 16> bit offset <integer_cst 0x2a95891d80 constant invariant 64> context <record_type 0x2a959dfe70>>>> The following testcase also ICEs on 32bit targets: typedef struct { struct { } z; } thang_t; struct { short e; thang_t f; int g; } my_struct; void function(int blaz) { thang_t *fp = &my_struct.f; foo(fp);} the important thing is that there has to be padding after e and the zero-sized f.
I have a fix.
Created attachment 11367 [details] patch Patch to be tested (Micha, can you do this?).
Yes. I'm testing it for trunk and 4.1 on a couple platforms.
Created attachment 11368 [details] patch relative to 4.1 This is the same patch adjusted for 4.1.
Subject: Bug 27409 Author: rguenth Date: Sun May 7 21:03:55 2006 New Revision: 113607 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113607 Log: 2006-05-07 Richard Guenther <rguenther@suse.de> PR tree-optimization/27409 * tree-ssa-structalias.c (get_constraint_for_component_ref): Do not try to find zero-sized subvars. * gcc.dg/torture/pr27409.c: New testcase. Added: trunk/gcc/testsuite/gcc.dg/torture/pr27409.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-ssa-structalias.c
Fixed at least on the mainline.
Subject: Bug 27409 Author: rguenth Date: Tue May 9 14:33:26 2006 New Revision: 113652 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113652 Log: 2006-05-09 Richard Guenther <rguenther@suse.de> PR tree-optimization/27409 * tree-ssa-structalias.c (get_constraint_for_component_ref): Do not try to find zero-sized subvars. * gcc.dg/torture/pr27409.c: New testcase. Added: branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/torture/pr27409.c Modified: branches/gcc-4_1-branch/gcc/ChangeLog branches/gcc-4_1-branch/gcc/testsuite/ChangeLog branches/gcc-4_1-branch/gcc/tree-ssa-structalias.c
Fixed.
Subject: Bug number PR27409 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-05/msg00153.html