[LLVMdev] Strange pointer aliasing behaviour

Andrew Haley aph at redhat.com
Thu Jun 17 10:04:54 PDT 2010


On 06/17/2010 05:54 PM, Jim Grosbach wrote:
> 
> On Jun 17, 2010, at 9:42 AM, Pierre C wrote:
> 
>>>> Consider a case like the following:
>>>> struct X { int a; int b[10]; };
>>>> int f(struct X* a) { a->b[-1] = 1; return a->a; }
>>>>
>>>> This is technically illegal code, but various programs depend on
>>>> constructs like this working.
>>
>> Actually if you want to do bit-casting in C the usual way is to
>> very carefully use an union which informs the compiler that there
>> will be aliasing...
>>
> 
> Quite right. Unfortunately, Eli is correct that there is a large
> codebase out there that uses less friendly idioms. It's getting
> better over time as people fix the issues (perhaps wishful thinking
> on my part), but it is still a "gotcha" we need to be aware of and
> consider when we make more aggressive optimizations.

Makes sense.  It would really make sense to conditionalize all this on
an option like gcc's -fstrict-aliasing.  As far as I know the Linux
kernel still needs this option to be turned off.

Andrew.



More information about the llvm-dev mailing list