[llvm-dev] RFC: On removing magic numbers assuming 8-bit bytes

James Courtier-Dutton via llvm-dev llvm-dev at lists.llvm.org
Mon May 6 02:12:42 PDT 2019

On Mon, 6 May 2019 at 09:26, Jesper Antonsson via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> I agree, addressable unit size is probably a better abstraction.
> However, in the lib/CodeGen directory alone, there's some 785 uses of
> the word "byte" and a significant fraction of the code that we want to
> modify is using the byte terminology today. An example of unmodified
> code from my showcase patch set:
>     assert(!(Shift & 0x7) == 0 &&
>            "Shifts not aligned on Bytes are not supported.");
>     uint64_t Offset = Shift / 8;
>     unsigned TySizeInBytes = Origin->getValueSizeInBits(0) / 8;
>     assert(!(Origin->getValueSizeInBits(0) & 0x7) == 0 &&
>            "The size of the original loaded type is not a
>            "multiple of a byte.");
> How would you prefer we handle this? If we only remove the magic
> numbers using getAddressableUnitSize() instead of getBitsPerByte() we'd
> get some mixed terminology. If the community is ok with that, we're
> happy to do this. If we would go for changing the terminology overall,
> then the work and the patch sizes would grow considerably.
Although the above is mentioning bytes, looking at the "/ 8"   and "& 0x7"
makes it look like the author meant octets and not bytes.
Bytes can be any size of bits. Octets are only ever 8 bits.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190506/b612ecde/attachment.html>

More information about the llvm-dev mailing list