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.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59105/new/

https://reviews.llvm.org/D59105



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D59105: [... Richard Smith - zygoloid via Phabricator via cfe-commits
    • [PATCH] D591... Erich Keane via Phabricator via cfe-commits
    • [PATCH] D591... Bevin Hansson via Phabricator via cfe-commits

Reply via email to