[LLVMdev] subtle problem with inst_iterator

Chris Lattner sabre at nondot.org
Fri Apr 23 08:52:02 PDT 2004


On Fri, 23 Apr 2004, Vladimir Prus wrote:
> and since result of *it is considered to be rvalue it can't be accepted by
> this operator. The complete discussion is in
>
>     http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1385.htm
>
> I'd suggest to apply the following patch which makes operator* return
> reference to pointer. It makes my code compile and the rest of LLVM compiles
> too. Comments?

Hrm, I'm not sure about this at all.  In particular ilists have some funny
semantics that you should know about.  In particular, the instruction list
is more like a std::list<Instruction> (but that allows polymorphism) than
a std::list<Instruction*>, so it's not possible to just assign a new
instruction* through an iterator.  In other words:  *iit = new
Instruction(...) doesn't make any sense.

Probably the right thing to do would be to make the inst_iterator return a
reference to the *instruction* itself, rather than a reference to the
pointer.  This would make it work the same as standard ilist iterators.
The reason why we have it return pointers right now is to populate
worklists, which allows us to do:

std::set<Instruction*> WorkList(inst_begin(F), inst_end(F));

Which is nice.

What do you think?

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/




More information about the llvm-dev mailing list