Why getNumOperands() incorrectly returns 0?

Hi all,
I have encountered a weird case that I cannot understand. Inside the visitStoreInst I have a reference (F) to the function png_set_mem_fn. If I do F->dump() i can set the IR of that function correctly e.g.:

; Function Attrs: nounwind uwtable
define void @png_set_mem_fn(%struct.png_struct_def.68* noalias %png_ptr, i8* %mem_ptr, i8* (%struct.png_struct_def.68*, i64)* %malloc_fn, void (%struct.png_struct_def.68*, i8*)* %free_fn) #5 {

}

The problem is that when I do F->getNumOperands() I have 0 as result.

Can you explain me why please?

Thanks

Hi Alberto,

The problem is that when I do F->getNumOperands() I have 0 as result.

Can you explain me why please?

You should think of a "Function *" like any other GlobalValue, in that
what you've got during your visit is really just @png_set_mem_fn. That
(pointer to a function) doesn't depend on any other LLVM values, so it
doesn't have any operands. If and when you call it, the Function will
continue to have no operands but the CallInst will have the operands
you're expecting to see here.

However, because it's a defined Function it does have other structure;
and if you want to look at what arguments it might take if you called
it, you need to use Function::arg_begin or related iterators. Because
there aren't actually any values associated with those arguments
outside the function body, you'll only be able to meaningfully use
their type (and maybe their name).

Cheers.

Tim.

Thanks Tim,
using arg_begin I solved my problem.

Thanks again