https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102937
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|FIXED |INVALID
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to David Rohr from comment #3)
> thanks, makes me feel pretty stupid...
> I thought it is not a problem since char* may alias, but apparently size_t*
> may not alias char**... if I understood correctly...
No, you are still misunderstand aliasing rules.
Basically you can access any type via a character type.
That is:
char *a = (char*)t;
a[n] = ...;
access *t
since you are doing basically:
char *a;
size_t *t = (size_t)&a;
*t = ....
access a
size_t only alias size_t and the signed version of what the type size_t was
typedef of (size_t is unsigned).
In the above case, you access "char*" as size_t which is undefined. if you
instead accessed it as char rather than size_t then the code would be well
defined.
That is:
char *a;
char *b = (char*)&a;
b[0] = ...
b[1] = ...
b[2] = ...
....
access a
There are other ways fixing the issue by using memcpy (or an union but an union
in this case is harder to use correctly) than extra assignments.