[llvm] [NFC][BOLT] fix DIE traversal incorrect loop termination condition. (PR #208450)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 9 06:10:29 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: Thrrreeee (Thrrreeee)

<details>
<summary>Changes</summary>

The DIE traversal loop in partitionCUs() used an incorrect termination condition, causing it to read past the end of the CU. Fix the loop to stop at NextCUOffset so traversal no longer runs beyond the unit's boundary.

Fixed [#<!-- -->208440](https://github.com/llvm/llvm-project/issues/208440).

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


1 Files Affected:

- (modified) bolt/lib/Rewrite/DWARFRewriter.cpp (+3-1) 


``````````diff
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 31bb74a6488a6..5e7b2a9e05aa8 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -591,6 +591,8 @@ static SmallVector<SmallVector<DWARFUnit *>> partitionCUs(DWARFContext &DwCtx,
     DWARFDataExtractor DebugInfoData = CU->getDebugInfoExtractor();
     DWARFDebugInfoEntry DIEEntry;
     SmallVector<uint32_t, 8> ParentIndex;
+    // The initial entry is an artificial root. The unit's terminating null DIE
+    // only pops back to this root, so stop before reading past NextCUOffset.
     ParentIndex.push_back(UINT32_MAX);
     do {
       if (!DIEEntry.extractFast(*CU, &DIEOffset, DebugInfoData, NextCUOffset,
@@ -622,7 +624,7 @@ static SmallVector<SmallVector<DWARFUnit *>> partitionCUs(DWARFContext &DwCtx,
       } else {
         ParentIndex.pop_back();
       }
-    } while (!ParentIndex.empty());
+    } while (DIEOffset < NextCUOffset);
   }
 
   DenseMap<DWARFUnit *, SmallVector<DWARFUnit *>> MembersByLeader;

``````````

</details>


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


More information about the llvm-commits mailing list