Skip to content

[NFC][DWARF][DebugInfo] Consolidate NextCUOffset checks #146958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tltao
Copy link
Contributor

@tltao tltao commented Jul 3, 2025

Some error checking code involving getNextUnitOffset() looks a bit strange and what is tested may not be equal to what is reported if any changes are made to getNextUnitOffset().

Change this so what is tested is consistent with what is reported. Also remove unnecessary calls when the value is already available in the function.

@llvmbot
Copy link
Member

llvmbot commented Jul 3, 2025

@llvm/pr-subscribers-debuginfo

Author: None (tltao)

Changes

Some error checking code involving getNextUnitOffset() looks a bit strange and what is tested may not be equal to what is reported if any changes are made to getNextUnitOffset().

Change this so what is tested is consistent with what is reported. Also remove unnecessary calls when the value is already available in the function.


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

2 Files Affected:

  • (modified) llvm/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp (+1-1)
  • (modified) llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp (+2-2)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp
index 4f0a6d96ace9e..06f0999b6e034 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp
@@ -30,7 +30,7 @@ bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint64_t *OffsetPtr,
                           "DWARF unit from offset 0x%8.8" PRIx64 " incl. "
                           "to offset 0x%8.8" PRIx64 " excl. "
                           "tries to read DIEs at offset 0x%8.8" PRIx64,
-                          U.getOffset(), U.getNextUnitOffset(), *OffsetPtr));
+                          U.getOffset(), UEndOffset, *OffsetPtr));
     return false;
   }
   assert(DebugInfoData.isValidOffset(UEndOffset - 1));
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
index ef59c82fc6a01..f19fa5a1169d5 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -294,9 +294,9 @@ Error DWARFUnitHeader::extract(DWARFContext &Context,
   // Header fields all parsed, capture the size of this unit header.
   assert(*offset_ptr - Offset <= 255 && "unexpected header size");
   Size = uint8_t(*offset_ptr - Offset);
-  uint64_t NextCUOffset = Offset + getUnitLengthFieldByteSize() + getLength();
+  uint64_t NextCUOffset = getNextUnitOffset();
 
-  if (!debug_info.isValidOffset(getNextUnitOffset() - 1))
+  if (!debug_info.isValidOffset(NextCUOffset - 1))
     return createStringError(errc::invalid_argument,
                              "DWARF unit from offset 0x%8.8" PRIx64 " incl. "
                              "to offset  0x%8.8" PRIx64 " excl. "

@redstar redstar requested a review from pogo59 July 4, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants