The testcase below aborts when compiled with -O2. ------------------------------------------------------------ union tree_node;
struct tree_common { int a; long b; long c; void *p; int d; }; struct other_tree { struct tree_common common; int arr[14]; }; struct tree_vec { struct tree_common common; int length; union tree_node *a[1]; }; union tree_node { struct other_tree othr; struct tree_vec vec; }; union tree_node global; union tree_node * __attribute__((noinline)) foo (union tree_node *p, int i) { union tree_node **q; p->vec.a[i] = (union tree_node *) 0; q = &p->vec.a[1]; *q = &global; return p->vec.a[i]; } extern void abort (void); extern void *malloc (__SIZE_TYPE__); int main() { union tree_node *p = malloc (sizeof (union tree_node)); if (foo (p, 1) != &global) abort (); return 0; } ------------------------------------------------------------ foo() is optimized to return NULL, most probably because get_ref_base_and_extent does not recognize that accesses to a do not necessarily have to have constant max_size. I have tried with trunk revision 152041 and 152147. The latter specifically is: jamb...@gcc16:~/gcc/test$ ~/gcc/inst/trunk/bin/gcc -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: /home/jamborm/gcc/trunk/configure --prefix=/home/jamborm/gcc/inst/trunk/ --enable-checking=release --enable-languages=c,c++ --disable-bootstrap --with-mpfr=/opt/cfarm/mpfr-2.3.2/ --disable-multilib Thread model: posix gcc version 4.5.0 20090924 (experimental) (GCC) -- Summary: Another get_ref_base_and_extent problem Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jamborm at gcc dot gnu dot org GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41463