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

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 8 05:06:08 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: Haojian Wu (hokein)

<details>
<summary>Changes</summary>

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).


---
Full diff: https://github.com/llvm/llvm-project/pull/115477.diff


1 Files Affected:

- (modified) llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h (+1-1) 


``````````diff
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:

``````````

</details>


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


More information about the llvm-commits mailing list