https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65270

--- Comment #21 from rguenther at suse dot de <rguenther at suse dot de> ---
On Wed, 4 Mar 2015, hubicka at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65270
> 
> --- Comment #16 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
> Richard,
> thanks, I also think alias trick makes gloal vars safe for merging across
> RESTRICT flags. 
> 
> One however needs to consider merging of items referring restricted vars.
> 
> const restrict int *a=&var;
> const int *b = &var; 
> 
> const int **ptrs1={&a};
> const int **ptrs2=[&b};
> 
> with -fmerge-all-constants we may merge ptrs1 and ptrs2 and, in the late
> compilation, in turn fold expression "ptrs2[0]" into a restricted pointer to
> var?

So we merge a and b with introducing an alias which is why we can
merge ptrs1 and ptrs2, correct?  But still with introducing an
alias.  But folding ptrs1[0] and ptrs2[0] will now return the same
(but random?) value.

Note that it's not folding that can introduce issues but points-to
analysis and what it computes for the globals ptrs1 and ptrs2
and thus for code that reads from them.

We are not really parsing constructors fully in PTA - at least I see

ptrs1 = NONLOCAL
ptrs1.0_2 = ptrs1
_3 = *ptrs1.0_2 
_4 = *_3        

only for

int var;
const int * restrict a=&var;
const int *b = &var;

const int * const *ptrs1={&a};
const int * const *ptrs2={&b};

int main()
{
  return *(ptrs1[0]);
}

IPA PTA does sth funny though:

ptrs2 = NONLOCAL
b = NONLOCAL
var = NONLOCAL
b = &var
ESCAPED = &var
ptrs2 = &b
ESCAPED = &b
ptrs1 = NONLOCAL
a = &GLOBAL_RESTRICT
GLOBAL_RESTRICT = NONLOCAL
ptrs1 = &a
ESCAPED = &a

but obviously we don't seem to merge ptrs1/ptrs2.  But IPA PTA
needs quite some thoughts with respect to aliases I think (and
in other ways as well...).

> If this case is legit, the correct place to match RESTRICT flags is
> compare_cgraph_references. We can also go with your patch that will make A and
> B considered to be different and thus prevent merging PTRS1&PTRS2.

That would certainly be a safe thing to do.

Even with -flto -fmerge-all-constants we don't get ptrs1 and ptrs2
merged it seems (with -fwhole-program we fold stuff too early).

Richard.

Reply via email to