[llvm] [BOLT][AArch64]`lookupStubFromGroup` Should Check the Last Element Instead of Returning `nullptr` When `lower_bound` Reaches End Iterator (PR #114015)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 29 01:16:56 PDT 2024
https://github.com/liusy58 created https://github.com/llvm/llvm-project/pull/114015
The current implementation of `lookupStubFromGroup` is incorrect. The function is intended to find and return the closest stub using `lower_bound`, which identifies the first element in a sorted range that is not less than a specified value. However, if such an element is not found within `Candidates` and the list is not empty, the function returns `nullptr`. Instead, it should check whether the last element satisfies the condition.
>From c0919e3b48ef08dee5740f4a944eb79d95277808 Mon Sep 17 00:00:00 2001
From: liusy58 <liusy58 at linux.alibaba.com>
Date: Tue, 29 Oct 2024 16:09:31 +0800
Subject: [PATCH] The current implementation of `lookupStubFromGroup` is
incorrect. The function is intended to find and return the closest stub using
`lower_bound`, which identifies the first element in a sorted range that is
not less than a specified value. However, if such an element is not found
within `Candidates` and the list is not empty, the function returns
`nullptr`. Instead, it should check whether the last element satisfies the
condition.
---
bolt/lib/Passes/LongJmp.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/bolt/lib/Passes/LongJmp.cpp b/bolt/lib/Passes/LongJmp.cpp
index 0b2d00300f46b9..77acd2decc9bd9 100644
--- a/bolt/lib/Passes/LongJmp.cpp
+++ b/bolt/lib/Passes/LongJmp.cpp
@@ -130,9 +130,9 @@ BinaryBasicBlock *LongJmpPass::lookupStubFromGroup(
const std::pair<uint64_t, BinaryBasicBlock *> &RHS) {
return LHS.first < RHS.first;
});
- if (Cand == Candidates.end())
- return nullptr;
- if (Cand != Candidates.begin()) {
+ if (Cand == Candidates.end()) {
+ Cand = std::prev(Cand);
+ } else if (Cand != Candidates.begin()) {
const StubTy *LeftCand = std::prev(Cand);
if (Cand->first - DotAddress > DotAddress - LeftCand->first)
Cand = LeftCand;
More information about the llvm-commits
mailing list