[LLVMdev] Strange pointer aliasing behaviour

Pierre C lists at peufeu.com
Thu Jun 17 09:42:13 PDT 2010


>> 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...

> Those programs are buggy and should be fixed.

Totally agree. Making such ugly things work means lots of optimizations  
can't be performed.

I wonder if llvm intentionnally generates this spurious alias (to make  
badly written code work) or is it just the optimizer not being smart  
enough yet ?...



More information about the llvm-dev mailing list