This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Missed integer promotion for array_ref?
- From: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 9 Feb 2005 16:09:16 +0100 (CET)
- Subject: Missed integer promotion for array_ref?
(last mail about all this unsigned vs. signed stuff...)
int a[1024];
int *bar(int i) { return a+i; }
int *foo(int i) { return &a[i]; }
is gimplified (for C++) to
int* bar(int) (i)
{
int * D.1566;
unsigned int i.0;
unsigned int D.1568;
int * D.1569;
i.0 = (unsigned int) i;
D.1568 = i.0 * 4;
D.1569 = (int *) D.1568;
D.1566 = D.1569 + &a[0];
return D.1566;
}
int* foo(int) (i)
{
int * D.1573;
int i.1;
i.1 = i;
D.1573 = &a[i.1];
return D.1573;
}
as i is not casted to unsigned int in foo(), &a[i] is not the same
as a + i here. Of course for negative i the results of bar and foo
are undefined anyway, but this difference in signdedness of the offset
of ARRAY_REF confuses the optimizers (and made me dig into this).
Richard.
--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/