llvmcpy icon indicating copy to clipboard operation
llvmcpy copied to clipboard

Setting function attributes fails with OverflowError

Open cgrenz opened this issue 8 years ago • 2 comments
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)

cgrenz avatar Apr 10 '17 12:04 cgrenz

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.

aleclearmind avatar Apr 10 '17 14:04 aleclearmind

Any progress on this?

aleclearmind avatar May 20 '19 10:05 aleclearmind