Page MenuHomeFreeBSD

Expose clang's alignment builtins and use them for roundup2/rounddown2
ClosedPublic

Authored by arichardson on Jan 25 2021, 3:08 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Dec 17, 12:19 PM
Unknown Object (File)
Tue, Dec 3, 4:57 PM
Unknown Object (File)
Oct 15 2024, 6:22 AM
Unknown Object (File)
Oct 15 2024, 6:22 AM
Unknown Object (File)
Oct 15 2024, 6:22 AM
Unknown Object (File)
Oct 15 2024, 6:09 AM
Unknown Object (File)
Sep 30 2024, 2:34 PM
Unknown Object (File)
Sep 30 2024, 2:16 PM
Subscribers
None

Details

Summary

This makes roundup2/rounddown2 type- and const-preserving and allows
using it on pointer types without casting to uintptr_t first. Not
performing pointer-to-integer conversions also helps the compiler's
optimization passes and can therefore result in better code generation.
When using it with integer values there should be no change other than
the compiler checking that the alignment value is a valid power-of-two.

I originally implemented these builtins for CHERI a few years ago and
they have been very useful for CheriBSD. However, they are also useful
for non-CHERI code so I was able to upstreamed them for Clang 10.0.

Rationale from the clang documentation:
Clang provides builtins to support checking and adjusting alignment
of pointers and integers. These builtins can be used to avoid relying
on implementation-defined behavior of arithmetic on integers derived
from pointers. Additionally, these builtins retain type information
and, unlike bitwise arithmetic, they can perform semantic checking on
the alignment value.

There is also a feature request for GCC, so GCC may also support it in
the future: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98641

Test Plan

amd64 world+kernel successful, currently running tinderbox

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 36467
Build 33356: arc lint + arc unit

Event Timeline

arichardson created this revision.
This revision is now accepted and ready to land.Jan 25 2021, 8:25 PM

Tinderbox just completely successfully (after applying D28331).

I'll go ahead and commit this next week unless anyone objects (or earlier if I get another approval from someone who has not worked with these builtins before).