[cfe-dev] Confusion about: ASTContext::toCharUnitsFromBits usage

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Sat Jun 22 13:42:46 PDT 2019


On Thu, 20 Jun 2019 at 07:14, Jeroen Dobbelaere via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi all,
>
> ASTContext::toCharUnitsFromBits is implemented as follows in
> clang/lib/AST/ASTContext.cpp [1]:
>
> ---
>   /// toCharUnitsFromBits - Convert a size in bits to a size in characters.
>   CharUnits ASTContext::toCharUnitsFromBits(int64_t BitSize) const {
>      return CharUnits::fromQuantity(BitSize / getCharWidth());
>   }
> ---
>
> Based on the comment, I would assume that the goal is to convert the
> BitSize into a number of characters
> that can contain the number of bits.
> The implementation though is rounding downwards, to the number of
> characters fitting in the BitSize.
>
> On a number of places [2], the function is called with a guarantee that
> the BitSize is a multiple of the CharWidth.
> On a recent change though [3], the patch depends on the downwards rounding
> behavior.
>
> Is this downwards rounding behavior the expected behavior for this
> function ?
>

We probably shouldn't be relying on that. Fixed in r364139.

Thanks,
>
> Jeroen Dobbelaere
> ----
> [1] https://clang.llvm.org/doxygen/ASTContext_8cpp_source.html#l02161
> [2]
> https://clang.llvm.org/doxygen/RecordLayoutBuilder_8cpp_source.html#l00769
>
> https://clang.llvm.org/doxygen/RecordLayoutBuilder_8cpp_source.html#l00781
> [3] https://reviews.llvm.org/D63371
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190622/e4067ffb/attachment.html>


More information about the cfe-dev mailing list