ApsarasX/llvm-bindings

Memory intrinsics not working

wintermute-motherbrain opened this issue · 2 comments

It seems that trying to access any of the memory intrinsic functions will cause a seg fault e.g.:

const memcpy = llvm.Intrinsic.getDeclaration(module, llvm.Intrinsic.memmove)

The intrinsic function highlighted in the test folder (debugtrap) does work but none of the memory related ones seem to work (memcpy, memcpy_inline, memmove, etc).

Also, thank you for putting this library together, its great to finally have access to the larger feature set of llvm through node!

As the llvm source code comment says:

The Tys parameter is for intrinsics with overloaded types (e.g., those
using iAny, fAny, vAny, or iPTRAny). For a declaration of an overloaded
intrinsic, Tys must provide exactly one type for each overloaded type in the intrinsic.

https://github.com/llvm/llvm-project/blob/6cad45d5c6f581e025106b8157541f10370faa08/llvm/include/llvm/IR/Intrinsics.h#L91-L98

You need to pass the third argument for llvm.Intrinsic.getDeclaration if you want to get memmove intrinsic.

I have given an example in test folder:

const memmoveFn = Intrinsic.getDeclaration(module, Intrinsic.memmove, [
builder.getInt8PtrTy(),
builder.getInt8PtrTy(),
builder.getInt32Ty()
]);

BTW, there is a small bug in parameter processing of Intrinsic.getDeclaration before v0.3.1. Please update llvm-bindings to v0.3.1

That was it! Cheers