[llvm] [MCA] use std::function instead of function_ref when storing (PR #91039)
Min-Yih Hsu via llvm-commits
llvm-commits at lists.llvm.org
Mon May 6 10:39:38 PDT 2024
mshockwave wrote:
> Passing a lambda directly to the set callback functions will end up causing UB/segfaults when the lambda is called as some external memory is now invalid. This is easy to work around (create a separate std::function, pass that into the function setting the callback), but isn't ideal.
Yeah, in that case it definitely creates a dangling function pointer.
My original motivation behind using `llvm::function_ref` over `std::function` was that the latter is not cheap and sometime pretty expensive, and presumably it's not really difficult for the users (of IncrementalSrcManager and InstrBuilder) to store/manage the callbacks somewhere else. Do you find cases where storing callbacks outside these two classes challenging?
https://github.com/llvm/llvm-project/pull/91039
More information about the llvm-commits
mailing list