Skip to content

AIX repr(C) struct layout does not always match C compiler #151910

@RalfJung

Description

@RalfJung

The layout rules for the f64 type on AIX are very special, and we do not always correctly implement them. #149880 improved the situation, but to my knowledge some cases are still wrong. @workingjubilee please correct be if I am wrong.

Our current best understanding of the rather confusingly-written documentation for this is that

  • f64 generally only has an alignment requirement of 4
  • However, sometimes f64 fields will be 8-aligned (and possibly this also affects fields of struct types where the struct contains f64)

In particular, we currently compute the wrong layout for this type:

#[repr(C)]
struct Struct {  
  a1: f64,
  a2: u8,
}

The size should be 16, but it is 12.

Another one (with the comments indicating what the layout should be):

// Size: 24
#[repr(C)]
struct Floats {  
  a: f64, // at offset 0
  b: u8, // at offset 8
  c: f64, // at offset 12
}

Currently we compute the same offsets but we give the type a size of 20.

This can't be fully fixed on the Rust side without something like rust-lang/rfcs#3845 to resolve the conflict between the platform C layout and using the standard layout algorithm that repr(C) uses everywhere else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-reprArea: the `#[repr(stuff)]` attributeO-aixOS: Big Blue's Advanced Interactive eXecutive..T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions