Skip to content

ty: Use underlying layout of typedefs if available. - #3453

Merged
emilio merged 1 commit into
mainfrom
over-aligned-typedef
Sep 6, 2026
Merged

ty: Use underlying layout of typedefs if available.#3453
emilio merged 1 commit into
mainfrom
over-aligned-typedef

Conversation

@emilio

@emilio emilio commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

This fixes struct layout issues with over-aligned typedefs, which rust can't represent, see #3449 for context and some other discussion.

This is kinda ugly tho, but as far as I can tell there's no good way of getting the right ABI and struct layout at the same time...

@emilio

emilio commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

cc @ojeda

This fixes struct layout issues with over-aligned typedefs, which
rust can't represent, see #3449 for context and some other discussion.

This is kinda ugly tho, but as far as I can tell there's no good way of
getting the right ABI and struct layout at the same time...
@emilio
emilio force-pushed the over-aligned-typedef branch from 5e6308c to 447f5f4 Compare September 6, 2026 19:38
@emilio
emilio added this pull request to the merge queue Sep 6, 2026
Merged via the queue into main with commit efb6e0c Sep 6, 2026
51 checks passed
@emilio
emilio deleted the over-aligned-typedef branch September 6, 2026 20:59
@ojeda

ojeda commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

A few more cases for your tests/future considerations:

struct Inner { long long a, b; };
typedef struct Inner AlignedInner __attribute__((aligned(16)));

struct Outer {
    long long before;
    AlignedInner inner[1];
};

(and the same with --opaque-type AlignedInner).

struct Inner { long long a, b; };
typedef struct Inner AlignedInner __attribute__((aligned(16)));
struct Outer {
    long long before;
    AlignedInner inner[0];
    char tail;
};
enum __attribute__((aligned(16))) AlignedEnum { Value = 1 };
struct Outer {
    long long before;
    enum AlignedEnum inner;
};
typedef unsigned int U __attribute__((aligned(2)));
struct Outer {
    char before;
    U bits : 31;
    char mid;
    U inner;
    char tail;
};

All these changed w.r.t. 0.72.1.

I hope that helps & thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants