[llvm-dev] Why getNumOperands() incorrectly returns 0?

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Sat Mar 16 01:44:48 PDT 2019


Hi Alberto,

On Sat, 16 Mar 2019 at 07:25, Alberto Barbaro via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> 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.


More information about the llvm-dev mailing list