[llvm] [symbolizer] Change the ErrorHandler from llvm::function_ref to std::function. (PR #115477)

Haojian Wu via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 8 05:05:37 PST 2024


https://github.com/hokein created https://github.com/llvm/llvm-project/pull/115477

This fixes dangling `ErrorHandler` references ([here](https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cpp#L48-L53) is an example).

`llvm::function_ref` doesn't own the callable, and it is not safe to store a function_ref (the `PlainPrinterBase` stores a `llvm::function_ref` which can easily lead to dangling references).


>From 36f5a52a73bdb5a332b88880e70911c70f3a5c2d Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Fri, 8 Nov 2024 09:46:22 +0100
Subject: [PATCH] [symbolizer] Change the ErrorHandler from llvm::function_ref
 to std::function.

---
 llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h b/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h
index 72ffdd29f1b72d..828875f1bb0ede 100644
--- a/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h
+++ b/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h
@@ -65,7 +65,7 @@ struct PrinterConfig {
   int SourceContextLines;
 };
 
-using ErrorHandler = function_ref<void(const ErrorInfoBase &, StringRef)>;
+using ErrorHandler = std::function<void(const ErrorInfoBase &, StringRef)>;
 
 class PlainPrinterBase : public DIPrinter {
 protected:



More information about the llvm-commits mailing list