<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body 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?<br>
<br>
<br>
<div class="moz-cite-prefix">On 2/19/15 8:17 PM, Nick Lewycky wrote:<br>
</div>
<blockquote
cite="mid:CADbEz-h8GE53qxcUXmiLffJBaJDohuAsZt1H2AZEH0EhWk=gwA@mail.gmail.com"
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 moz-do-not-send="true"
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>
</body>
</html>