[llvm] [Sample Profile Loader] Fix potential invalidated reference (PR #73181)

William Junda Huang via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 22 16:37:31 PST 2023


huangjd wrote:

> how to prevent similar problems (adding while iterating)?

There's no general solution, as this is a "feature" in C++ that the user is responsible for checking that. I searched other usages of hash maps in SampleProfile* to make sure there's no more use case like that (or use map which does not invalidate reference).

The problem can be detected with memory sanitizer.

Developers should be careful especially working with graphs, because it is likely to involve pointers onto a map. 

 

https://github.com/llvm/llvm-project/pull/73181


More information about the llvm-commits mailing list