Getting the parent memoryLocation

Hello All

I am currently writing an analysis pass that needs to find the memory locations of the arguments in a CallInst. I am using the following API at the moment:


I am having issues using this when I pass arguments whose memory was allocated using the malloc function call. For example, in the following LLVM-IR snippet:

%call = tail call noalias dereferenceable_or_null(4) i8* @malloc(i64 noundef 4) #6
%3 = bitcast i8* %call to float*
%call2 = call float @function_check(float* noundef nonnull %3, float* noundef nonnull %d, i32 noundef %2)

Here the first argument should point to the malloc function, but because there is a cast operation in-between, the MemoryLocation points to this cast instruction, rather than the malloc instructiion.

Is there any API/LLVM pass that can help me to get the source location for the function argument?


You can use Value->stripPointerCasts() to look through bitcasts (and similar operations, like zero-offset GEPs).

Thanks a lot! That works!