<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 19 February 2015 at 16:07, Haopeng Liu <span dir="ltr"><<a href="mailto:hyliuhp@gmail.com" target="_blank">hyliuhp@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi,<br>
<br>
I'm trying to explore basicaa alias analysis.<br>
<br>
test.c:<br>
int main() {<br>
    int a;<br>
    int *p, *q;<br>
    p = &a;<br>
    q = p;<br>
    ...<br>
}<br>
<br>
Commands:<br>
clang -emit-llvm -c -g -O0 test.c -o test.bc<br>
opt -basicaa -print-must-aliases test.bc<br>
<br>
However, the result shows that p and q are no alias.<br>
<br>
Could anyone explain it? Your help is much appreciated!<br></blockquote><div><br></div><div>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.</div><div><br></div><div>Here's the IR for test.bc:<br></div><div><br></div><div>define i32 @main() {<br></div><div><div>entry:</div><div>  %a = alloca i32, align 4</div><div>  %p = alloca i32*, align 8</div><div>  %q = alloca i32*, align 8</div><div>  store i32* %a, i32** %p, align 8</div><div>  %0 = load i32** %p, align 8</div><div>  store i32* %0, i32** %q, align 8</div><div>  ret i32 0</div><div>}</div></div><div><br></div><div>%p and %q do not alias, they are two separate pointers into the stack.</div><div><br></div><div>Nick</div></div></div></div>