<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 19 February 2015 at 19:19, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
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?</div></blockquote><div><br></div><div>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.</div><div><br></div><div>Nick</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div text="#000000" bgcolor="#FFFFFF"><div><div class="h5"><div>On 2/19/15 8:17 PM, Nick Lewycky wrote:<br>
</div>
<blockquote type="cite">
<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>
</blockquote>
<br>
</div></div></div>
</blockquote></div></div></div>