* sparse-llvm functions must be cast to correct type before calling
@ 2017-03-16 20:58 Dibyendu Majumdar
2017-03-19 0:20 ` Luc Van Oostenryck
0 siblings, 1 reply; 2+ messages in thread
From: Dibyendu Majumdar @ 2017-03-16 20:58 UTC (permalink / raw)
To: Linux-Sparse
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: sparse-llvm functions must be cast to correct type before calling
2017-03-16 20:58 sparse-llvm functions must be cast to correct type before calling Dibyendu Majumdar
@ 2017-03-19 0:20 ` Luc Van Oostenryck
0 siblings, 0 replies; 2+ messages in thread
From: Luc Van Oostenryck @ 2017-03-19 0:20 UTC (permalink / raw)
To: Dibyendu Majumdar; +Cc: Linux-Sparse
On Thu, Mar 16, 2017 at 08:58:25PM +0000, Dibyendu Majumdar wrote:
> Hi,
>
> The following test (adapted from snippet posted by Linus) fails in sparse-llvm:
...
> 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():
This is a very general problem with sparse-llvm, directly caused
by the fact the sparse associates type to instructions and LLVM
to the values.
What's happening is that the first time a pseudo is used
it's a value is created (with the curret type, of course)
*and* is stored in the pseudo::priv.
The next times this pseudo is used the LLVM value is directly
taken from the ::priv without regards for the current type.
In the coming update of the LLVM serie, I added an helper
for this sort of things: adjust_type(). But it need to be
added at the right place(s).
-- Luc
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-03-19 0:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-16 20:58 sparse-llvm functions must be cast to correct type before calling Dibyendu Majumdar
2017-03-19 0:20 ` Luc Van Oostenryck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.