Alberto Barbaro via llvm-dev
2019-Mar-16 07:25 UTC
[llvm-dev] 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190316/4375e976/attachment.html>
Tim Northover via llvm-dev
2019-Mar-16 08:44 UTC
[llvm-dev] Why getNumOperands() incorrectly returns 0?
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.
Alberto Barbaro via llvm-dev
2019-Mar-18 18:23 UTC
[llvm-dev] Why getNumOperands() incorrectly returns 0?
Thanks Tim, using arg_begin I solved my problem. Thanks again Il giorno sab 16 mar 2019 alle ore 08:45 Tim Northover < t.p.northover at gmail.com> ha scritto:> 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. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190318/d9dd9fd5/attachment.html>