[llvm-dev] Find all assignment for pointer variables

George Burgess IV via llvm-dev llvm-dev at lists.llvm.org
Wed Jan 27 20:11:42 PST 2016


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>


More information about the llvm-dev mailing list