From 1c80fd134627952a2e4e2ce0644bb599c792cae9 Mon Sep 17 00:00:00 2001 From: Ken Dyck Date: Tue, 15 Mar 2011 01:09:02 +0000 Subject: 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. llvm-svn: 127641 --- clang/lib/CodeGen/CGExprConstant.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen/CGExprConstant.cpp') diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 0975d256ba7..59317f2a29d 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/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; -- cgit v1.2.3