[PATCH] D158689: [llvm-profdata] Fix dangling reference after D147740

Wenlei He via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 21:57:33 PDT 2023


wenlei added a comment.

> Fix a dangling reference bug in ProfileConverter::flattenNestedProfile . This is an existing bug only revealed after D147740 <https://reviews.llvm.org/D147740> changes the profile map container type.

Actually this is not true. Before D147740 <https://reviews.llvm.org/D147740>, SampleProfileMap is a unordered_map, which guarantees reference stability. See the follow statement from https://cplusplus.com/reference/unordered_map/unordered_map/rehash/

> If a rehash happens, all iterators are invalidated, but references and pointers to individual elements remain valid. If no actual rehash happens, no changes.

Implementations are depending on reference stability of SampleProfileMap to simplify things. And your change in D147740 <https://reviews.llvm.org/D147740> broke that. As evident by the various breakages and reverts, such change is dangerous and can be impactful. I suggest you restore reference stability for SampleProfileMap, otherwise they may be more breakages from your change yet to be uncovered.

Would `HashKeyMap<unordered_map, SampleContext, FunctionSamples>` be enough to restore reference stability?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158689/new/

https://reviews.llvm.org/D158689



More information about the llvm-commits mailing list