[LLVMdev] For alias analysis, It's gcc too aggressive or LLVM need to improve?
Tim Northover
t.p.northover at gmail.com
Fri Aug 8 04:54:50 PDT 2014
> your C program invokes undefined behavior when it dereferences pointers that
> have been converted to other types. See for example
> http://stackoverflow.com/questions/4810417/c-when-is-casting-between-pointer-types-not-undefined-behavior
I don't think it's quite that simple.The type-based aliasing rules
come from 6.5p7 of C11, I think. That says:
"An object shall have its stored value accessed only by an lvalue
expression that has one of
the following types:
+ a type compatible with the effective type of the object,
[...]
+ an aggregate or union type that includes one of the aforementioned
types among its members [...]"
That would seem to allow this usage: aa (effective type "int") is
being accessed via an lvalue "ptr[i]->index" of type "int".
The second point would even seem to allow something like "ptr[i] =
..." if aa was declared "int aa[2];", though that seems to be going
too far. It also seems to be very difficult to pin down a meaning
(from the standard) for "a->b" if a is not a pointer to an object with
the correct effective type. So the entire area is probably one that's
open to interpretation.
I've added cfe-dev to the list; they're the *professional* language lawyers.
Cheers.
Tim.
More information about the llvm-dev
mailing list