Skip to main content

DataLayout

Struct DataLayout 

Source
pub struct DataLayout {
Show 17 fields pub char_is_signed: bool, pub short_size: u64, pub int_size: u64, pub long_size: u64, pub long_long_size: u64, pub long_long_align: u64, pub pointer_size: u64, pub pointer_align: u64, pub float: FloatType, pub double: FloatType, pub long_double: FloatType, pub wchar_size: u64, pub wchar_is_signed: bool, pub leading_underscore: bool, pub bitfield_order: BitfieldOrder, pub max_field_align: Option<u64>, pub has_int128: bool,
}
Expand description

The type sizes and alignments a target’s headers were written against.

Everything here is a fact the psABI states and the compiler has to agree with. None of it is something C decides, which is the point: two compilers can both implement C correctly and disagree about every field in this struct, and the one that disagrees with the target’s headers is the one that is wrong.

Fields§

§char_is_signed: bool

Whether a plain char is signed.

§short_size: u64

The width of a short in bytes, which is two everywhere on the target list.

§int_size: u64

The width of an int in bytes.

§long_size: u64

The width of a long in bytes, which is the field the old three field triple got wrong for every 64-bit Windows target.

§long_long_size: u64

The width of a long long in bytes.

§long_long_align: u64

What a long long is aligned to.

Four on System V i386, where it is eight bytes aligned to four, which is spec/cross-compile/06-abis.md section 6.2 item 2’s example of a layout rule that is not derivable from the member alignments. Eight under mingw on the same architecture.

§pointer_size: u64

The width of a pointer in bytes.

§pointer_align: u64

What a pointer is aligned to.

§float: FloatType

float.

§double: FloatType

double.

§long_double: FloatType

long double, which is the one that differs across almost every target.

§wchar_size: u64

The width of a wchar_t in bytes, which decides what a wide string literal is encoded in.

Two on Windows, so a wide string there is UTF-16 and a character outside the basic plane takes two elements, and four everywhere else, where it is UTF-32 and no character takes more than one. It is the operating system’s answer and not the architecture’s, which facts/aarch64-windows-msvc.facts and facts/aarch64-linux-gnu.facts show as a pair.

§wchar_is_signed: bool

Whether a wchar_t is signed.

A separate fact from DataLayout::char_is_signed and not derivable from it. AArch64 FreeBSD makes both unsigned, AArch64 NetBSD makes char unsigned and wchar_t signed, and Windows makes char signed and wchar_t unsigned, so no rule over one of them answers the other. L'\xffffffff' is minus one where this is true and four billion where it is false.

§leading_underscore: bool

Whether a symbol gets a leading underscore, which is section 6.2 item 11.

§bitfield_order: BitfieldOrder

Which end of a storage unit a bit-field starts at.

§max_field_align: Option<u64>

The largest alignment the ABI will give a struct member on its own, in bytes, and None where there is no cap.

Four on System V i386 and eight on s390x. A cap is invisible until a program uses a sixteen byte type inside a struct, and then it is a layout difference rather than an error.

§has_int128: bool

Whether the target has __int128.

It is a fact about the architecture and not about the pointer width, which is the trap: x86_64-linux-gnux32 has four byte pointers and the type, and i686-linux-gnu has four byte pointers and not the type. Both references provide it wherever the machine has sixty four bit registers to hold half of it in, and refuse it everywhere else.

Implementations§

Source§

impl DataLayout

Source

pub fn for_target(target: TargetTuple) -> Self

The layout for this target.

Every field is derived from the tuple rather than from the host, which is spec/cross-compile/08-sysroots.md section 8.5’s rule applied to types instead of to directories, and it is what makes spec/cross-compile/02-the-goal.md claim 5 checkable: two hosts asking about the same target get the same answer because there is nothing in here for the host to influence.

Source

pub const fn long_double_is_double(&self) -> bool

Whether a long double is really a double, which is true on Darwin, under MSVC and on every 32-bit ARM target, and which decides whether %Lf and LDBL_MAX and the l suffixed math functions mean anything different from their unsuffixed forms.

Trait Implementations§

Source§

impl Clone for DataLayout

Source§

fn clone(&self) -> DataLayout

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DataLayout

Source§

impl Debug for DataLayout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DataLayout

Source§

impl PartialEq for DataLayout

Source§

fn eq(&self, other: &DataLayout) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DataLayout

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.