[llvm] Fix size in bytes of type DIEs when size in bits is not a multiple of 8 (PR #69741)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 20 10:25:38 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: Augusto Noronha (augusto2112)

<details>
<summary>Changes</summary>

The existing code will always round down the size in bits when calculating the size in bytes (for example, a types with 1-7 bits will be emitted as 0 bytes long). Fix this by always rounding up, which would be the minimum amount of bytes to fit the size in bits.

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


1 Files Affected:

- (modified) llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (+1-1) 


``````````diff
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index d30f0ef7af348af..b61660b189236fb 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -874,7 +874,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
   // Add name if not anonymous or intermediate type.
   StringRef Name = CTy->getName();
 
-  uint64_t Size = CTy->getSizeInBits() >> 3;
+  uint64_t Size = (CTy->getSizeInBits() + 7) >> 3;
   uint16_t Tag = Buffer.getTag();
 
   switch (Tag) {

``````````

</details>


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


More information about the llvm-commits mailing list