struct C { unsigned int c; struct D { unsigned int columns : 4; unsigned int fore : 9; unsigned int back : 9; unsigned int fragment : 1; unsigned int standout : 1; unsigned int underline : 1; unsigned int strikethrough : 1; unsigned int reverse : 1; unsigned int blink : 1; unsigned int half : 1; unsigned int bold : 1; unsigned int invisible : 1; unsigned int pad : 1; } attr; }; struct A { struct C *data; unsigned int len; }; struct B { struct A *cells; unsigned char soft_wrapped : 1; }; struct E { long row, col; struct C defaults; }; __attribute__ ((noinline)) void foo (struct E *screen, unsigned int c, int columns, struct B *row) { struct D attr; long col; int i; col = screen->col; attr = screen->defaults.attr; attr.columns = columns; row->cells->data[col].c = c; row->cells->data[col].attr = attr; col++; attr.fragment = 1; for (i = 1; i < columns; i++) { row->cells->data[col].c = c; row->cells->data[col].attr = attr; col++; } } int main (void) { struct E e = {.row = 5,.col = 0,.defaults = {6, {-1, -1, -1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}} }; struct C c[4]; struct A a = { c, 4 }; struct B b = { &a, 1 }; struct D d; __builtin_memset (&c, 0, sizeof c); foo (&e, 65, 2, &b); d = e.defaults.attr; d.columns = 2; if (__builtin_memcmp (&d, &c[0].attr, sizeof d)) __builtin_abort (); d.fragment = 1; if (__builtin_memcmp (&d, &c[1].attr, sizeof d)) __builtin_abort (); return 0; } is miscompiled at -O1 and above, works with -fno-tree-sra.
Introduced in r132969. During esra we have: D.1656_34 = VIEW_CONVERT_EXPR<unsigned int>(screen_3(D)->defaults.attr); D.1657_35 = D.1656_34 >> 23; attr$B23F9_36 = (<unnamed-unsigned:9>) D.1657_35; ... SR.8_37 = attr$B23F9_36 >> 7; SR.9_50 = (unsigned int) SR.8_37; SR.10_51 = SR.9_50 << 23; SR.11_52 = SR.7_49 | SR.10_51; D.1634_19->attr ={v} VIEW_CONVERT_EXPR<struct D>(SR.11_52); That >> 7 is either wrong, or lacks corresponding << 7.
Mine.
Subject: Bug 39339 Author: rguenth Date: Wed Mar 4 09:02:59 2009 New Revision: 144598 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144598 Log: 2009-03-04 Richard Guenther <rguenther@suse.de> PR tree-optimization/39339 * tree-sra.c (try_instantiate_multiple_fields): Make it no longer ICE on the above. * gcc.c-torture/execute/pr39339.c: New testcase. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr39339.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-sra.c
Fixed.