This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Testcase for strict-aliasing wanted
- From: Geoff Keating <geoffk at geoffk dot org>
- To: Osku Salerma <osku at iki dot fi>
- Cc: gcc at gcc dot gnu dot org
- Date: 18 Jan 2002 12:29:04 -0800
- Subject: Re: Testcase for strict-aliasing wanted
- References: <Pine.LNX.4.20.0201182134180.736-100000@127>
Osku Salerma <osku@iki.fi> writes:
> Does anybody have a simple testcase available that breaks with strict
> aliasing enabled? I tried to construct my own, but I can't get either
> 2.95.2 or the latest CVS version to break intentionally. Either I'm
> misunderstanding some of the aliasing rules or gcc isn't optimizing as
> aggressively in this case as would be needed for the aliasing issues
> to surface.
>
> For reference, here's my (not-working) effort:
>
> #include <stdio.h>
>
> void f(char* p1, int* p2)
> {
> char c1,c2;
>
> c1 = *p1;
> *p2 = 0;
> c2 = *p1;
>
> printf("(%d,%d)\n", c1,c2);
> }
>
> int main(void)
> {
> char a[4];
>
> a[0] = 1;
>
> f(a, (int*)a);
>
> return 0;
> }
`char' is a special case; ISO C requires that it be allowed to alias
with anything. Try the same testcase with `short' instead of `char'.
--
- Geoffrey Keating <geoffk@geoffk.org> <geoffk@redhat.com>