I wrote some program using DensMap like this:
==============================SmallDenseMap<Value*, StringRef, 4>
OpResult;
Value *VP = GEP->getPointerOperand();
OpResult[VP] = parseVariable(VP);
for(User::op_iterator sId = GEP->idx_begin(), eId = GEP->idx_end(); sId
!= eId; ++sId) {
Value *VI = *sId;
if(dyn_cast<ConstantInt>(*sId)) OpResult[VI] =
parseConstant(VI);
else OpResult[VI] = parseVariable(VI);
}
....
==============================When I visit OpResult like this:
====================std::string result = OpResult[VP];
====================And this statement changes the other data in DenseMap. Why?
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.