Kai Wang via llvm-dev
2016-Jan-28 03:30 UTC
[llvm-dev] Find all assignment for pointer variables
Hi all, In my case, I want to find all assignment instructions for pointer variables. For example, int *d, *c; *d = *c; I want to know there is an assignment between *d and *c. Here is the IR: %3 = load i32** %c, align %4 = load i32* %3, align 4 %5 = load i32** %d, align 8 store i32 %4, i32* %5, align 4 There are some temp variable %3, %4, %5. Is there any way to find the assignment "*d = *c" from IR? Or should I look into clang AST? Thank you. -- Regards, Kai -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160127/0cedfd55/attachment.html>
George Burgess IV via llvm-dev
2016-Jan-28 04:11 UTC
[llvm-dev] Find all assignment for pointer variables
It depends on what you're trying to do. If you're just looking for "*d = *c" as a source-level pattern, then clang's AST will be your best bet. You may find ASTMatchers to be highly useful. If you're new to working with clang, writing simple programs and "compiling" them with `clang -cc1 -ast-dump my_program_name.c` will give you a very detailed picture of what the AST for my_program_name.c looks like. If you want to find all of the places in a program that can store to some arbitrary memory location pointed to by `d`, you need to work with LLVM IR. And good luck, because that's a really difficult problem to solve. :) George On Wed, Jan 27, 2016 at 7:30 PM, Kai Wang via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi all, > In my case, I want to find all assignment instructions for pointer > variables. > For example, > int *d, *c; > *d = *c; > > I want to know there is an assignment between *d and *c. > > Here is the IR: > > %3 = load i32** %c, align > > %4 = load i32* %3, align 4 > > %5 = load i32** %d, align 8 > > store i32 %4, i32* %5, align 4 > There are some temp variable %3, %4, %5. Is there any way to find the > assignment "*d = *c" from IR? > Or should I look into clang AST? > > Thank you. > -- > Regards, > Kai > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160127/3878f11c/attachment.html>