[llvm] Fix size in bytes of type DIEs when size in bits is not a multiple of 8 (PR #69741)
Augusto Noronha via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 10:24:28 PDT 2023
https://github.com/augusto2112 created https://github.com/llvm/llvm-project/pull/69741
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.
>From 0582dc1a3a5b16fd1af5e985fadf10ae88ec9092 Mon Sep 17 00:00:00 2001
From: Augusto Noronha <augusto2112 at me.com>
Date: Fri, 20 Oct 2023 10:18:03 -0700
Subject: [PATCH] Fix size in bytes of type DIEs when size in bits is not a
multiple of 8
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.
---
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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) {
More information about the llvm-commits
mailing list