sparse-llvm functions must be cast to correct type before calling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

The following test (adapted from snippet posted by Linus) fails in sparse-llvm:

typedef unsigned int (*binop_t)(int, int);
typedef unsigned int (*unop_t)(int);
extern int printf(const char *, ...);
#define BINOP 0
#define UNOP 1
static unsigned int execute(int type, void *fn, int arg1, int arg2)
{
 if (type == BINOP)
  return ((binop_t)fn)(arg1,arg2);
 return ((unop_t)fn)(arg1);
}
static unsigned int unary(int arg1)
{
 return arg1+3;
}
int main(void)
{
 return execute(UNOP, unary, 3, 10) == 6 ? 0 : 1;
}

To resolve this before calling a function we need to cast it to the
expected type. This can be done like this in output_op_call():

 struct symbol *ftype = get_function_basetype(insn->fntype);

...

 LLVMTypeRef function_type = symbol_type(C, fn->module, ftype);
 LLVMTypeRef fptr_type = LLVMPointerType(function_type, 0);
 LLVMTypeRef bytep = LLVMPointerType(LLVMInt8Type(), 0);
 target = LLVMBuildBitCast(fn->builder, func, bytep, name);
 target = LLVMBuildBitCast(fn->builder, target, fptr_type, name);
 target = LLVMBuildCall(fn->builder, target, args, n_arg, name);
 insn->target->priv = target;


Thanks and Regards
Dibyendu
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux