[llvm] [lsan][llvm-profdata] Suppress leak check on abnormal exit (PR #219088)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 18:56:00 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-pgo

Author: Vitaly Buka (vitalybuka)

<details>
<summary>Changes</summary>

This is common issue with lsan after exit().
`exit()` is no return, we can't expect that compiler
will preserve pointers to allocations done by callers.


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


1 Files Affected:

- (modified) llvm/tools/llvm-profdata/llvm-profdata.cpp (+15) 


``````````diff
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index 49c645598f475..216d881f00720 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -50,6 +50,17 @@
 #include <cmath>
 #include <optional>
 
+#if LLVM_ADDRESS_SANITIZER_BUILD || LLVM_HWADDRESS_SANITIZER_BUILD
+#include <sanitizer/lsan_interface.h>
+static int SkipLeakCheck;
+LLVM_ATTRIBUTE_USED int __lsan_is_turned_off() { return SkipLeakCheck; }
+static void skipLeakCheck() {
+  SkipLeakCheck = 1;
+}
+#else
+static void skipLeakCheck() {}
+#endif
+
 using namespace llvm;
 using ProfCorrelatorKind = InstrProfCorrelator::ProfCorrelatorKind;
 
@@ -533,6 +544,10 @@ static void exitWithError(Twine Message, StringRef Whence = "",
   errs() << Message << "\n";
   if (!Hint.empty())
     WithColor::note() << Hint << "\n";
+  // exit() terminates without unwinding the stack or running destructors, and
+  // there is no guaranty that pointers to allocations will be preserved, so
+  // LSan reports in-flight heap allocations as leaks at atexit.
+  skipLeakCheck();
   ::exit(1);
 }
 

``````````

</details>


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


More information about the llvm-commits mailing list