[PATCH] D40339: Use getStoreSize() in various places instead of BitSize >> 3

Jonas Paulsson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 01:42:05 PST 2017


jonpa updated this revision to Diff 124702.
jonpa added a comment.
Herald added a subscriber: JDevlieghere.

> Your way of implementing getSizeInBytes() is having some flaws

Aah, sorry - seems I was just handling i1. Thanks for the suggestion. Now all tests are still green...

(Sorry for hard-coding the ByteSizeInBits to 8 once again, but it should save you two instances in total ;-)


https://reviews.llvm.org/D40339

Files:
  include/llvm/IR/DebugInfoMetadata.h
  lib/CodeGen/AsmPrinter/DwarfUnit.cpp


Index: lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -813,14 +813,14 @@
   addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
           BTy->getEncoding());
 
-  uint64_t Size = BTy->getSizeInBits() >> 3;
+  uint64_t Size = BTy->getSizeInBytes();
   addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
 }
 
 void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy) {
   // Get core information.
   StringRef Name = DTy->getName();
-  uint64_t Size = DTy->getSizeInBits() >> 3;
+  uint64_t Size = DTy->getSizeInBytes();
   uint16_t Tag = Buffer.getTag();
 
   // Map to main type, void will not have a type.
@@ -907,7 +907,7 @@
   // Add name if not anonymous or intermediate type.
   StringRef Name = CTy->getName();
 
-  uint64_t Size = CTy->getSizeInBits() >> 3;
+  uint64_t Size = CTy->getSizeInBytes();
   uint16_t Tag = Buffer.getTag();
 
   switch (Tag) {
Index: include/llvm/IR/DebugInfoMetadata.h
===================================================================
--- include/llvm/IR/DebugInfoMetadata.h
+++ include/llvm/IR/DebugInfoMetadata.h
@@ -594,6 +594,7 @@
   unsigned getLine() const { return Line; }
   uint64_t getSizeInBits() const { return SizeInBits; }
   uint32_t getAlignInBits() const { return AlignInBits; }
+  uint64_t getSizeInBytes() const { return ((SizeInBits + 7) / 8); }
   uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
   uint64_t getOffsetInBits() const { return OffsetInBits; }
   DIFlags getFlags() const { return Flags; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40339.124702.patch
Type: text/x-patch
Size: 1658 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171129/7fb89251/attachment.bin>


More information about the llvm-commits mailing list