From: Ken Dyck Date: Fri, 18 Mar 2011 00:55:06 +0000 (+0000) Subject: Convert variables to CharUnits in ConvertStructToPacked(). No change in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4a5c87ec3b92026523a6459f5b4547c4a9b5ab24;p=clang Convert variables to CharUnits in ConvertStructToPacked(). No change in functionality intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127844 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 9034cdee59..59480a0323 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -297,36 +297,36 @@ void ConstStructBuilder::AppendTailPadding(CharUnits RecordSize) { void ConstStructBuilder::ConvertStructToPacked() { std::vector PackedElements; - uint64_t ElementOffsetInBytes = 0; + CharUnits ElementOffsetInChars = CharUnits::Zero(); for (unsigned i = 0, e = Elements.size(); i != e; ++i) { llvm::Constant *C = Elements[i]; unsigned ElementAlign = CGM.getTargetData().getABITypeAlignment(C->getType()); - uint64_t AlignedElementOffsetInBytes = - llvm::RoundUpToAlignment(ElementOffsetInBytes, ElementAlign); + CharUnits AlignedElementOffsetInChars = + ElementOffsetInChars.RoundUpToAlignment( + CharUnits::fromQuantity(ElementAlign)); - if (AlignedElementOffsetInBytes > ElementOffsetInBytes) { + if (AlignedElementOffsetInChars > ElementOffsetInChars) { // We need some padding. - uint64_t NumBytes = - AlignedElementOffsetInBytes - ElementOffsetInBytes; + CharUnits NumChars = + AlignedElementOffsetInChars - ElementOffsetInChars; const llvm::Type *Ty = llvm::Type::getInt8Ty(CGM.getLLVMContext()); - if (NumBytes > 1) - Ty = llvm::ArrayType::get(Ty, NumBytes); + if (NumChars > CharUnits::One()) + Ty = llvm::ArrayType::get(Ty, NumChars.getQuantity()); llvm::Constant *Padding = llvm::UndefValue::get(Ty); PackedElements.push_back(Padding); - ElementOffsetInBytes += getSizeInBytes(Padding); + ElementOffsetInChars += CharUnits::fromQuantity(getSizeInBytes(Padding)); } PackedElements.push_back(C); - ElementOffsetInBytes += getSizeInBytes(C); + ElementOffsetInChars += CharUnits::fromQuantity(getSizeInBytes(C)); } - assert(CharUnits::fromQuantity(ElementOffsetInBytes) == - NextFieldOffsetInChars && + assert(ElementOffsetInChars == NextFieldOffsetInChars && "Packing the struct changed its size!"); Elements = PackedElements;