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
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 0975d25..59317f2 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -77,7 +77,11 @@
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 @@
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;