0
votes

I want to create a function in LLVM that takes a pointer to arbitrary memory from store instructions. For example:

%x = alloca i32, align 4
%z = alloca i32*, align 8
store i32 123, i32* %x, align 4
store i32* %x, i32** %z, align 8

Here, I want to instrument the store instructions to invoke a function with the memory pointers which are once of type i32* and once of type i32**. I only need the "first pointer" to memory and I don't need to derenference the pointers or get its type information. So, I need a datatype that is similar to void pointers in C.

How can I do that in LLVM?

1
bitcast from i32* to i8*? - Frank C.
If there is no void* like type, then casting every pointer to i8* might be the best solution. You could make an answer - user2600312

1 Answers

1
votes

Here is an example of casting both %x and %y to a void*

  %x = alloca i32, align 4
  %y = alloca i32*, align 8
  store i32 123, i32* %x, align 4
  store i32* %x, i32** %y, align 8

  ; Convert x to void*

  %1 = bitcast i32* %x to i8*
  call void @instrument(i8* %1)

  ; Convert y to void*

  %2 = load i32*, i32** %y, align 8
  %3 = bitcast i32* %2 to i8*
  call void @instrument(i8* %3)