This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: DR#236 analysis
- From: Paul Schlie <schlie at comcast dot net>
- To: <gcc at gcc dot gnu dot org>
- Date: Fri, 03 Dec 2004 19:36:08 -0500
- Subject: Re: DR#236 analysis
> Geoff Keating writes:
> I see. Yes, that's not what I meant. In this case, the type of the malloc-ed
> memory is 'struct elf_link_hash_entry', and that's what's not allowed to
> change; what I want prohibited is code like:
>
> void * mem = malloc (max (sizeof (int), sizeof (float));
> *(int *)mem = 1;
> *(float *)mem = 2.0;
>
> where the top-level type of the memory changes.
What's wrong with conservatively assuming that a pointer may alias
cumulatively any object type if ever explicitly dereferences, where
a dereferenced union is equivalent to it's cumulative set of types.)
(i.e. logical equivalent to your example, mem :: int*, float*, or void*)
Where then if someone wants to take advantage of potential optimizations;
they should use pointers conservatively, and ideally explicitly declare
them as not being aliased if enabled by the language.
As it would seem to be better to be safe than sorry, and not unnecessarily
restrict programmers to accomplish what they want to do, with the
understanding that there may be consequences to their decisions.