This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: aliasing between const and non-const objects
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: Michael Matz <matz at suse dot de>
- Cc: gcc at gcc dot gnu dot org, Richard dot Earnshaw at arm dot com
- Date: Tue, 29 Jul 2003 17:05:07 +0100
- Subject: Re: aliasing between const and non-const objects
- Organization: ARM Ltd.
- Reply-to: Richard dot Earnshaw at arm dot com
> 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.