aliasing between const and non-const objects
Richard Earnshaw
rearnsha@arm.com
Tue Jul 29 16:46:00 GMT 2003
> 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.
More information about the Gcc
mailing list