Skip to content

Commit 7ecdf62

Browse files
[MCA] use std::function instead of function_ref when storing (#91039)
This patch changes uses of llvm::function_ref for std::function when storing the callback inside of a class. The LLVM Programmer's manual mentions that llvm::function_ref is not safe to store as it contains pointers to external memory that are not guaranteed to exist in the future when it is stored. This causes issues when setting callbacks inside of a class that manages MCA state. 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.
1 parent dce197a commit 7ecdf62

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

llvm/include/llvm/MCA/IncrementalSourceMgr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class IncrementalSourceMgr : public SourceMgr {
4141
bool EOS = false;
4242

4343
/// Called when an instruction is no longer needed.
44-
using InstFreedCallback = llvm::function_ref<void(Instruction *)>;
44+
using InstFreedCallback = std::function<void(Instruction *)>;
4545
InstFreedCallback InstFreedCB;
4646

4747
public:

llvm/include/llvm/MCA/InstrBuilder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ class InstrBuilder {
7979
bool FirstCallInst;
8080
bool FirstReturnInst;
8181

82-
using InstRecycleCallback =
83-
llvm::function_ref<Instruction *(const InstrDesc &)>;
82+
using InstRecycleCallback = std::function<Instruction *(const InstrDesc &)>;
8483
InstRecycleCallback InstRecycleCB;
8584

8685
Expected<const InstrDesc &>

0 commit comments

Comments
 (0)