Closed arichardson closed 6 years ago
I believe this is now ready to merge if there are no objections.
Looks good to me, though it's worth sticking it in LLVM Phabricator before we start adopting it too widely, in case they want it to have a different spelling.
Yep looks good to me too
This adds
__builtin_is_aligned(ptr, align)
,__builtin_align_up(ptr, align)
,__builtin_align_down(ptr, align)
. I also added builtins that take a powers of two exponent instead an alignment byte value. They work on pointers, integers and capabilities and always return the same type as the first argument. For integer values they perform masking of the integer value and a cast back to a pointer. For CHERI they compute the difference to the next aligned value and then use a CIncOffset to align the value.Currently the non-power-of-two versions of the builtins only take integer constants whereas the p2 versions accept any value. After implementing the test cases I feel like it is probably silly to only allow constants in order to check that they are powers-of-two. Should I change it to allow any value as an argument and just garbage if a value that is not a power of two is passed. Maybe this should be checked this with a ubsan checker at runtime instead?