From 6925cc498be5d363ac7fb235dc6650fd7da5f2f2 Mon Sep 17 00:00:00 2001 From: Ken Dyck Date: Tue, 15 Mar 2011 01:09:02 +0000 Subject: [PATCH] Introduce a CharUnits FieldOffsetInChars variable in AppendField() to replace some uses of FieldOffsetInBytes. The remaining uses of FieldOffsetInBytes will be replaced once NextFieldOffsetInBytes is converted to CharUnits. No change in functionality intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127641 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 0975d256ba..59317f2a29 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -77,7 +77,11 @@ private: bool ConstStructBuilder:: AppendField(const FieldDecl *Field, uint64_t FieldOffset, llvm::Constant *InitCst) { - uint64_t FieldOffsetInBytes = FieldOffset / 8; + + const ASTContext &Context = CGM.getContext(); + + CharUnits FieldOffsetInChars = Context.toCharUnitsFromBits(FieldOffset); + uint64_t FieldOffsetInBytes = FieldOffsetInChars.getQuantity(); assert(NextFieldOffsetInBytes <= FieldOffsetInBytes && "Field offset mismatch!"); @@ -100,9 +104,9 @@ AppendField(const FieldDecl *Field, uint64_t FieldOffset, if (AlignedNextFieldOffsetInBytes < FieldOffsetInBytes) { // We need to append padding. AppendPadding( - CharUnits::fromQuantity(FieldOffsetInBytes - NextFieldOffsetInBytes)); + FieldOffsetInChars - CharUnits::fromQuantity(NextFieldOffsetInBytes)); - assert(NextFieldOffsetInBytes == FieldOffsetInBytes && + assert(NextFieldOffsetInBytes == FieldOffsetInChars.getQuantity() && "Did not add enough padding!"); AlignedNextFieldOffsetInBytes = NextFieldOffsetInBytes; -- 2.40.0