1
Fork 0

Use the Align type when parsing alignment attributes

This commit is contained in:
beetrees 2024-03-24 01:03:39 +00:00
parent 2f090c30dd
commit 6e5f1dacf3
No known key found for this signature in database
GPG key ID: 8791BD754191EBD6
12 changed files with 74 additions and 26 deletions

View file

@ -698,6 +698,7 @@ impl fmt::Display for AlignFromBytesError {
impl Align {
pub const ONE: Align = Align { pow2: 0 };
pub const EIGHT: Align = Align { pow2: 3 };
// LLVM has a maximal supported alignment of 2^29, we inherit that.
pub const MAX: Align = Align { pow2: 29 };
@ -707,19 +708,19 @@ impl Align {
}
#[inline]
pub fn from_bytes(align: u64) -> Result<Align, AlignFromBytesError> {
pub const fn from_bytes(align: u64) -> Result<Align, AlignFromBytesError> {
// Treat an alignment of 0 bytes like 1-byte alignment.
if align == 0 {
return Ok(Align::ONE);
}
#[cold]
fn not_power_of_2(align: u64) -> AlignFromBytesError {
const fn not_power_of_2(align: u64) -> AlignFromBytesError {
AlignFromBytesError::NotPowerOfTwo(align)
}
#[cold]
fn too_large(align: u64) -> AlignFromBytesError {
const fn too_large(align: u64) -> AlignFromBytesError {
AlignFromBytesError::TooLarge(align)
}