https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65270
--- Comment #23 from rguenther at suse dot de <rguenther at suse dot de> --- On Thu, 5 Mar 2015, hubicka at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65270 > > --- Comment #19 from Jan Hubicka <hubicka at gcc dot gnu.org> --- > I tried to construct a testcase for __restrict__ case: > int var; > const int *varptr=&var; > const int *__restrict__ varptr2=&var; > > int *__restrict__ varptr3 = &var; > int *__restrict__ varptr4 = &var; > > int * > return_valptr(int i) > { > return varptr[i]; > } > int * __restrict__ > return_valptr2(int i) > { > return varptr2[i]; > } > int > testrestrict () > { > int *ptr = return_valptr (0); > *ptr = 0; > *varptr3 = 1; > return *ptr; > } > int > testrestrict2 () > { > int *ptr = return_valptr2 (0); > *ptr = 0; > *varptr3 = 1; > return *ptr; > } > int > testrestrict4 () > { > *varptr4 = 0; > *varptr3 = 1; > return *varptr4; > } > > Here I would like restrict2 to return uncondtional 0, because ptr is taken > from > a restrict pointer in a global var. For whatever reason this optimization is > not happening (it happens in testrestrict4). So perhaps we are safe to > completely ignore restircts on vars, because we never get the flag in through > folding. We don't get it ever from folding. Only IPA PTA looks at global constructors, local PTA doesn't - but that's a missed optimization at least for readonly vars. Can you please open a new bug with the above testcase?