[LLVMdev] basicaa result

Nick Lewycky nlewycky at google.com
Fri Feb 20 11:31:05 PST 2015


On 19 February 2015 at 19:19, Haopeng Liu <hyliuhp at gmail.com> wrote:

>  It makes sense. Does llvm provide alias analysis on c/c++ which can
> figure out whether two different pointers in local stack point to same
> memory?
>

No. LLVM knows nothing about C/C++ at all. Clang also does not provide such
an analysis, but if there were one in the llvm project it would go under
clang.

Nick


> On 2/19/15 8:17 PM, Nick Lewycky wrote:
>
>  On 19 February 2015 at 16:07, Haopeng Liu <hyliuhp at gmail.com> wrote:
>
>> Hi,
>>
>> I'm trying to explore basicaa alias analysis.
>>
>> test.c:
>> int main() {
>>     int a;
>>     int *p, *q;
>>     p = &a;
>>     q = p;
>>     ...
>> }
>>
>> Commands:
>> clang -emit-llvm -c -g -O0 test.c -o test.bc
>> opt -basicaa -print-must-aliases test.bc
>>
>> However, the result shows that p and q are no alias.
>>
>> Could anyone explain it? Your help is much appreciated!
>>
>
>  LLVM's alias analysis works on LLVM IR, not on C. The conversion from C
> to LLVM IR is not as straight-forward as you might at first imagine; for
> instance, there is no address-of operation in LLVM. Write your examples in
> LLVM IR, or use clang to produce those examples from C code, but look at
> the IR it has produced and start thinking about AA results from there.
>
>  Here's the IR for test.bc:
>
>  define i32 @main() {
>  entry:
>   %a = alloca i32, align 4
>   %p = alloca i32*, align 8
>   %q = alloca i32*, align 8
>   store i32* %a, i32** %p, align 8
>   %0 = load i32** %p, align 8
>   store i32* %0, i32** %q, align 8
>   ret i32 0
> }
>
>  %p and %q do not alias, they are two separate pointers into the stack.
>
>  Nick
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150220/b6a96b58/attachment.html>


More information about the llvm-dev mailing list