<div dir="ltr"><div dir="ltr">On Thu, 20 Jun 2019 at 07:14, Jeroen Dobbelaere via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br>
<br>
ASTContext::toCharUnitsFromBits is implemented as follows in clang/lib/AST/ASTContext.cpp [1]:<br>
<br>
---<br>
  /// toCharUnitsFromBits - Convert a size in bits to a size in characters.<br>
  CharUnits ASTContext::toCharUnitsFromBits(int64_t BitSize) const {<br>
     return CharUnits::fromQuantity(BitSize / getCharWidth());<br>
  }<br>
---<br>
<br>
Based on the comment, I would assume that the goal is to convert the BitSize into a number of characters<br>
that can contain the number of bits. <br>
The implementation though is rounding downwards, to the number of characters fitting in the BitSize.<br>
<br>
On a number of places [2], the function is called with a guarantee that the BitSize is a multiple of the CharWidth.<br>
On a recent change though [3], the patch depends on the downwards rounding behavior.<br>
<br>
Is this downwards rounding behavior the expected behavior for this function ? <br></blockquote><div><br></div><div>We probably shouldn't be relying on that. Fixed in r364139.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thanks,<br>
<br>
Jeroen Dobbelaere<br>
----<br>
[1] <a href="https://clang.llvm.org/doxygen/ASTContext_8cpp_source.html#l02161" rel="noreferrer" target="_blank">https://clang.llvm.org/doxygen/ASTContext_8cpp_source.html#l02161</a><br>
[2] <a href="https://clang.llvm.org/doxygen/RecordLayoutBuilder_8cpp_source.html#l00769" rel="noreferrer" target="_blank">https://clang.llvm.org/doxygen/RecordLayoutBuilder_8cpp_source.html#l00769</a><br>
      <a href="https://clang.llvm.org/doxygen/RecordLayoutBuilder_8cpp_source.html#l00781" rel="noreferrer" target="_blank">https://clang.llvm.org/doxygen/RecordLayoutBuilder_8cpp_source.html#l00781</a><br>
[3] <a href="https://reviews.llvm.org/D63371" rel="noreferrer" target="_blank">https://reviews.llvm.org/D63371</a><br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>