[llvm-dev] DenseMap/ValueMap: is M[New]=M[Old] valid ?

Jeroen Dobbelaere via llvm-dev
Thu, 26 Sep 2019 21:48:04 -0000

Hi,

I have a question about llvm/ADT/DenseMap.h and llvm/IR/ValueMap.h:

When you have a:
     MapType M;

is it safe to do:
    M[NewKey] = M[OldKey];

or do you need to do it in two steps:
   auto tmp = M[OldKey]; // ensure the reference to M[OldKey] is copied, before
reassigning.
   M[NewKey] = tmp;      // might reallocate

aka, will a possible allocation for M[NewKey] invalidate the reference that
M[OldKey] returns ?

Greetings,

Jeroen Dobbelaere