[llvm] [MIRSampleProfile] Check nullptr Reader to avoid crash when profile file missing (PR #190186)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 08:01:17 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-pgo
Author: Frank515 (frank-515)
<details>
<summary>Changes</summary>
Fixes #<!-- -->189764
When the profile sample use file is not found, Reader is nullptr and causes a crash in MIRProfileLoader::runOnFunction.
This patch adds a null check at the beginning of the function to avoid the nullptr dereference.
---
Full diff: https://github.com/llvm/llvm-project/pull/190186.diff
1 Files Affected:
- (modified) llvm/lib/CodeGen/MIRSampleProfile.cpp (+2)
``````````diff
diff --git a/llvm/lib/CodeGen/MIRSampleProfile.cpp b/llvm/lib/CodeGen/MIRSampleProfile.cpp
index 1f00446465c12..e2b31f9afb46d 100644
--- a/llvm/lib/CodeGen/MIRSampleProfile.cpp
+++ b/llvm/lib/CodeGen/MIRSampleProfile.cpp
@@ -317,6 +317,8 @@ bool MIRProfileLoader::runOnFunction(MachineFunction &MF) {
// discriminator would end up getting zero samples. This could in turn undo
// the sample distribution effort done by previous BFI maintenance and the
// probe distribution factor work for pseudo probes.
+ if (!Reader)
+ return false;
if (!Reader->profileIsFS())
return false;
``````````
</details>
https://github.com/llvm/llvm-project/pull/190186
More information about the llvm-commits
mailing list