Mapping LLVM type i1 to Julia type

I am trying to use llvmcall and want to map a return value of LLVM type i1 to a Julia Bool value.

using Base

function isodd(a)
    Base.llvmcall("""%mod = srem i64 %0, 2\n%cmp = icmp eq i64 %mod, 1\nret i1 %cmp""", Bool, Tuple{Int64,}, a)


The following error is thrown when executing the program:

ERROR: LoadError: Failed to parse LLVM assembly: 
llvmcall:5:5: error: value doesn't match function result type 'i8'
ret i1 %cmp

Could anyone help? Is there an alternative type I can use instead of Bool to match to i1?

You need to zero extend it to i8. See


Thanks for the answer. But would it be possible to do this without changing the LLVM code, and by adding some compatible Julia type?

I don’t think so. Even primitive type restricts the size to be a multiple of 8.


FWIW, I haven’t seen an example where LLVM fails to get rid of the zext/truncs.