This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/28073] Type-punned pointer passed as function parameter generates bad assembly sequence
- From: "dberlin at dberlin dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Jun 2006 18:55:41 -0000
- Subject: [Bug c/28073] Type-punned pointer passed as function parameter generates bad assembly sequence
- References: <bug-28073-12847@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from dberlin at gcc dot gnu dot org 2006-06-19 18:55 -------
Subject: Re: Type-punned pointer passed as function parameter
generates bad assembly sequence
sorenj at us dot ibm dot com wrote:
> ------- Comment #2 from sorenj at us dot ibm dot com 2006-06-19 16:44 -------
> Changing just one line of the test program to the (AFAIK) legal C code. By
> casting through void *, we are addressing Andrew's concerns about violating the
> C rules.
No you aren't.
The only thing that matters is what the type of the dereferenced pointer
is, not the intermediate casts.
For example,
int *foo
float b;
float *c;
b = 5.0
foo = (int*)&b
c = (float *)foo
printf("%f\n", *c);
is legal.
>
> Foo *pFoo = *(Foo **) ((void *)&longPtr); /* // BAD! */
Still not legal.
>
> eliminates the type-punned warning, even at the highest possible warning level,
> and continues to generate code the results in a bad return value. This test
> case illustrates that this problem is actually worse than we originally
> thought, as now incorrect code is generated without any warning.
We can't issue warnings in every case because it is impossible to detect
every case.
We could probably issue a warning in this case.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28073