[llvm-dev] Question about a May-alias case

Friedman, Eli via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 13 16:17:52 PDT 2018


On 6/13/2018 3:50 PM, JinGu wrote:
> Let's slightly change the example as below.
>
> char subbuf1[2];
> char subbuf2[2];
> char subbuf3[2];
> char subbuf4[2];
> char *buf[4] = {subbuf1, subbuf2, subbuf3, subbuf4};
> char c;
> void test(int idx) {
>   char *a = buf[3 - idx];
>   char *b = buf[idx];
>   *a = *b;
>   c++;
>   *a = *b;
> }
>
> I think we can say the 'buf' does not point 'c'.

That doesn't help... the compiler still can't prove whether some other 
translation unit modifies buf.

If you declare buf as `char *const buf[4] = {subbuf1, subbuf2, subbuf3, 
subbuf4};`, then I guess you could prove that the pointers in buf don't 
point to c.  But that's a rare pattern in practice, and it would be kind 
of expensive to analyze in BasicAA.  Maybe if we add stateful AA to LLVM 
eventually.

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project



More information about the llvm-dev mailing list