All of lore.kernel.org
 help / color / mirror / Atom feed
* sparse-llvm functions are defined with a different name due to multiple attempts to add same function
@ 2017-03-14 13:11 Dibyendu Majumdar
  0 siblings, 0 replies; only message in thread
From: Dibyendu Majumdar @ 2017-03-14 13:11 UTC (permalink / raw)
  To: Linux-Sparse

Sparse-llvm appears to ignore prototypes, and declares a function when
first seen as a pseudo. However by doing this, when the function
definition is actually encountered in the code, it declares a few
function - and LLVM gives it a new name. Thus the original function is
not defined at all.

To resolve this, firstly we should not ignore prototypes.
Secondly when defining a function we should check if the function is
already declared.
Thirdly - the definition of functions from pseudos is probably no
longer necessary if we insist on seeing function prototype or
definition prior to use.

I added following function in sparse-llvm:

static void output_prototype(struct dmr_C *C, LLVMModuleRef module,
struct symbol *sym)
{
 const char *name = show_ident(C, sym->ident);
 struct symbol *base_type = sym;
 if (sym->type == SYM_NODE)
  base_type = sym->ctype.base_type;
 LLVMTypeRef ftype = sym_func_type(C, module, base_type);
 LLVMValueRef result = LLVMGetNamedFunction(module, name);
 if (!result) {
  result = LLVMAddFunction(module, name, ftype);
  LLVMSetLinkage(result, function_linkage(C, sym));
 }
 sym->priv = result;
}

I changed compile() to call above.

  if (is_prototype(sym)) {
   output_prototype(C, module, sym);
   continue;
  }

I also changed output_fn to first check if the function has already
been declared:

 function.fn = LLVMGetNamedFunction(module, name);
 if (!function.fn) {
  function.type = LLVMFunctionType(return_type, arg_types, nr_args,
base_type->variadic);
  function.fn = LLVMAddFunction(module, name, function.type);
  LLVMSetLinkage(function.fn, function_linkage(C, sym));
  sym->priv = function.fn;
 }
 else {
  function.type = LLVMTypeOf(function.fn);
 }

Thanks and Regards
Dibyendu

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-03-14 13:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-14 13:11 sparse-llvm functions are defined with a different name due to multiple attempts to add same function Dibyendu Majumdar

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.