How to identify malloc for specific structures

Hi all,
I want to find all of the malloc instructions for a specific structure. While malloc’s paramter is an integer, and return a opaque pointer in llvm-15, i don’t know how to identify it. For the C code below,
How to identify that s3 is s1, s4 is s2, or s3 is malloc for int, s4 for float

int *a = (int *)malloc(sizeof(int)) // s1
float *b = (float *) malloc(sizeof(double)) // s2

>
%3 = call noalias ptr @malloc(i64 noundef 4) // s3
%4 = call noalias ptr @malloc(i64 noundef 4) // s4

Thanks

You can’t, that information gets thrown away after the Clang AST. Though you should be very careful, because it does not matter what type you use for sizeof so long as the result is big enough.

1 Like

Thanks for reply, I understand :grinning: