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]

[RFH] Folding of &a[-1]


Hi!

While trying to implement folding of &a +- cst to &a[c] I came
along the C frontend, which for

   int a[4];
   int *p = &a[-1];

produces

   p = &a + (int *)-4;

so my new transformation gets

<integer_cst 0x401b5738 type <pointer_type 0x401559b4> constant invariant
4294967292>

as (int *)-4.

But of course trying to fold the index back into an ARRAY_REF, thereby
adjusting for the element size does not preserve the unsigned pointer
overflow behavior and I get

   &a[-4U/4] from &a[-1]

which is of course not the same.

Any idea how to avoid this kind of mess and still fold &a + cst
to an ARRAY_REF if appropriate?

Thanks,
Richard.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/


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