This is an archive of the discontinued LLVM Phabricator instance.

DataLayout::getPointerSize() should always return a power of 2
Needs ReviewPublic

Authored by stephenneuendorffer on Mar 30 2022, 12:34 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Previously, we expanded the behavior of DataLayout to allow representing
pointer sizes with an arbitrary number of bits, with the expectation
that most users would migrate to the getPointerSizeInBits API. We
implemented some backward compatibility for the getPointerSize() API to
return the minimum number of bytes needed to contain a poitner. However
it appears that there are some APIs, in particular, uses around Dwarf
Debug information where the pointer model is more constrained and
are expected to be a power 2.

This patch updates getPointerSize() in these cases return a power of
2 number of bytes. NFC for in-tree code since these architectures
already have a pointer size that is a power of 2.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2022, 12:34 PM
stephenneuendorffer requested review of this revision.Mar 30 2022, 12:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2022, 12:34 PM
stephenneuendorffer retitled this revision from DataLayout::getPointerSize() should always return a power of 2 (#89) to DataLayout::getPointerSize() should always return a power of 2.
arsenm added a subscriber: arsenm.Mar 30 2022, 2:04 PM

I don't think rounding this to a power of 2 fundamentally makes sense, and uses relying on that behavior should be adjusted to do something else.

I would also generally be suspicious of places using getPointerSize that really care about memory as it doesn't account for the declared alignment