[LLVMdev] Puzzles on DenseMap

Tim Northover t.p.northover at gmail.com
Sun Aug 25 05:32:43 PDT 2013


Hi,

> SmallDenseMap<Value*, StringRef, 4> OpResult;
> [...]
> std::string result = OpResult[VP];
> =====================
> And this statement changes the other data in DenseMap. Why?

There's not really enough information in what you've posted to say
definitively, but most likely is that the objects behind the
StringRefs have stopped existing at some point. StringRefs don't make
copies or extend the lifetime of what they're referring to.

If parseConstant/parseVariable return a StringRef to a local
std::string for example then that object will be destroyed as part of
the return and anything could happen after that point.

Cheers.

Tim.



More information about the llvm-dev mailing list