This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: aliasing between const and non-const objects


> Hi,
> 
> Suppose you wanted to fix such testcase:
> -------
> int *t;
> const int *c;
> void f (void)
> {
>   t[0] = c[0] + c[1] + c[2];
>   t[1] = c[0] + c[1] + c[2];
> }
> -------
> 
> With fixing I mean to make CSE recognize the redundant second summation.
> This is possible because the write to t[0] can't alias with the values
> load from c[].
> 

Incorrect.  External code could quite legitimately be:

foo()
{
  int a[5];

  t = a; c = a;
  f();
}

All that const on a pointer type says is that accesses through this 
instance must be const -- the underlying object need not be.

R.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]