[libunwind] [libunwind] fix pc range condition check bug (PR #154902)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 22 00:24:01 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libunwind

Author: Wu Yingcong (yingcong-wu)

<details>
<summary>Changes</summary>

There is an off-by-one error with current condition check for PC fallen into the range or not. There is another check within libunwind that use the correct checks in https://github.com/llvm/llvm-project/blob/5050da7ba18fc876f80fbeaaca3564d3b4483bb8/libunwind/src/UnwindCursor.hpp#L2757
```
      if ((fdeInfo.pcStart <= pc) && (pc < fdeInfo.pcEnd))
```

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


1 Files Affected:

- (modified) libunwind/src/DwarfParser.hpp (+1-1) 


``````````diff
diff --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index 7e85025dd054d..25250e0810987 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -273,7 +273,7 @@ bool CFI_Parser<A>::findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart,
           pint_t pcRange = addressSpace.getEncodedP(
               p, nextCFI, cieInfo->pointerEncoding & 0x0F);
           // Test if pc is within the function this FDE covers.
-          if ((pcStart < pc) && (pc <= pcStart + pcRange)) {
+          if ((pcStart <= pc) && (pc < pcStart + pcRange)) {
             // parse rest of info
             fdeInfo->lsda = 0;
             // check for augmentation length

``````````

</details>


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


More information about the cfe-commits mailing list