llvmcpy
llvmcpy copied to clipboard
Setting function attributes fails with OverflowError
trafficstars
Setting a function attribute with add_attribute_at_index() and AttributeFunctionIndex fails with
OverflowError: can't convert negative number to unsigned
This seems to be because the LLVM headers define LLVMAttributeFunctionIndex as -1, but LLVMAttributeIndex is a typedef for unsigned and CFFI doesn't allow negative values for unsigned integer parameters.
Test Case:
from llvmcpy import llvm
kind = llvm.get_enum_attribute_kind_for_name('noinline', len('noinline'))
attr = llvm.get_global_context().create_enum_attribute(kind, 0)
module = llvm.module_create_with_name('testmodule')
func = module.add_function('testfunction', llvm.void_type().function([], False))
func.add_attribute_at_index(llvm.AttributeFunctionIndex, attr)
I guess the only way to handle this is to convert each integer argument to the correct type before forwarding it to the CFFI wrapper. A bit annoying, but doable.
Thanks for reporting this.
Any progress on this?