Jeroen Dobbelaere via llvm-dev
2019-Sep-26 21:48 UTC
[llvm-dev] DenseMap/ValueMap: is M[New]=M[Old] valid ?
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
David Blaikie via llvm-dev
2019-Sep-26 21:51 UTC
[llvm-dev] DenseMap/ValueMap: is M[New]=M[Old] valid ?
Yep - You'd have to separate them for correctness if "NewKey" might not already be in "M". On Thu, Sep 26, 2019 at 2:48 PM Jeroen Dobbelaere via llvm-dev < llvm-dev at lists.llvm.org> wrote:> 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 > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190926/3b990f01/attachment.html>
Martin Storsjö via llvm-dev
2019-Sep-27 05:58 UTC
[llvm-dev] DenseMap/ValueMap: is M[New]=M[Old] valid ?
I actually ran into an elusive bug with this exact same issue some time ago as well, see https://bugs.llvm.org/show_bug.cgi?id=42065 and https://reviews.llvm.org/D62624. The strange thing about that bug was that it only showed up if built with GCC; Clang dereferenced the right hand side reference before evaluating the left hand side, as long as the value type was as small as the reference itself. // Martin On Thu, 26 Sep 2019, David Blaikie via llvm-dev wrote:> Yep - You'd have to separate them for correctness if "NewKey" might not > already be in "M". > > On Thu, Sep 26, 2019 at 2:48 PM Jeroen Dobbelaere via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > 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
Apparently Analagous Threads
- DenseMap/ValueMap: is M[New]=M[Old] valid ?
- DenseMap/ValueMap: is M[New]=M[Old] valid ?
- [LLVMdev] compile error when using overloaded = operator of DenseMap
- [LLVMdev] compile error when using overloaded = operator of DenseMap
- are the LLD libraries thread safe?