[PATCH] D59105: [RFC] Create an Arbitrary Precision Integer Type.

Bevin Hansson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 11 07:47:24 PDT 2019

ebevhan added inline comments.

Comment at: lib/AST/ASTContext.cpp:1687-1693
+  // toCharUnitsFromBits always rounds down, which isn't a problem when the size
+  // Width is a multiple of chars, however ArbPrecInt makes this not a valid
+  // assumption.
+  return std::make_pair(toCharUnitsFromBits(Info.Width) +
+                            (Info.Width % getCharWidth() == 0
+                                 ? CharUnits::Zero()
+                                 : CharUnits::One()),
rsmith wrote:
> This should not be necessary. `getTypeInfo` should not be returning sizes that are not a multiple of the bit-width of `char`.
Is this really an invariant of `getTypeInfo`? We have struck upon this issue downstream as well, as we have types which are not a multiple of the char size. The assumption in many places seems to be that when faced with scalar types, `getTypeInfo` does return the true bit width, not the width in chars*char width. `getTypeInfoInChars` obviously cannot handle this case, since it uses `getTypeInfo` as a basis for its calculation.

This is an issue for essentially any non-record, non-array type (such as typedefs or elaborated types) which consists of non-char-width types. Direct array types only work as there is a fast path (`getConstantArrayInfoInChars`) which does the per-element calculation correctly, and record types work because that calculation is delegated to the record layout builder.



More information about the cfe-commits mailing list