I wrote some program using DensMap like this:
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.