[LLVMdev] The use iterator not working...

Zack Waters zswaters at gmail.com
Tue Jun 9 19:02:04 PDT 2015


Hi,

I'm having a problem with the use iterator. Each "use" that I see, when
using the use_iterator, is the same as the "def". Meaning, in the code
below the pDef is always equal to pUse pointer for every instruction in all
basic blocks (except terminators).

            for (auto i = inst_begin(f), ie = inst_end(f); i != ie; ++i)

                Instruction* pDef = &(*i);
                errs() << "Def: " << *pDef << "\n";

                for (auto ui = pDef->use_begin(), uie = pDef->use_end(); ui
!= uie; ++ui)
                {
                    Instruction* pUse = dyn_cast<Instruction>(*ui);
                    errs() << "  Use: \t" << *pUse << "\n";
                }
            }

However, everything works as expected when using the range-based use
iterator with the following code.

            for (auto i = inst_begin(f), ie = inst_end(f); i != ie; ++i)
            {
                Instruction* pDef = &(*i);
                errs() << "Def: " << *pDef << "\n";

                for (User* pUser : pDef->users())
                {
                    Instruction* pUse = dyn_cast<Instruction>(pUser);
                    errs() << "  Use: \t" << *pUse << "\n";
                }
            }

Also, the code is executed inside a function pass. So was initially
thinking I somehow screwed up the use information in a previous pass.
However, I would assume the range-based iterator would not work as well but
it does.

Finally, I'm currently using LLVM 3.5.1 built for Windows. Google hasn't
been much help. Anybody have any suggestions as to why the first example
above doesn't work?

Thanks,
Zack
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150609/4bd8e11a/attachment.html>


More information about the llvm-dev mailing list