In my case, I want to find all assignment instructions for pointer variables.
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?
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.