Stream: cranelift

Topic: Alignment and padding of structs


view this post on Zulip Yorick Peterse (Dec 23 2023 at 00:32):

In LLVM there are routines to get the bit size of a type while taking padding and what not into account. I'm using this to figure out if a returned structure needs to use a regular return or a struct return.

Looking at the Cranelift documentation it seems it doesn't offer anything for this (in part because structures aren't really a thing in the IR). Am I correct in this?

view this post on Zulip Yorick Peterse (Dec 23 2023 at 00:32):

Implementing this myself isn't too hard, but it would be nice if I don't have to repeat something already done by others :smile:

view this post on Zulip Chris Fallin (Dec 23 2023 at 00:55):

That’s correct, Cranelift has no aggregate types; it’s up to you to compute struct layout and derive pointers appropriately

view this post on Zulip Yorick Peterse (Dec 23 2023 at 00:59):

Gotcha :smile:

view this post on Zulip scottmcm (Jan 03 2024 at 19:43):

You could try using https://doc.rust-lang.org/std/alloc/struct.Layout.html#method.extend for it, but as you say it's not that hard so whether it'd be worth it isn't necessarily obvious.


Last updated: Dec 23 2024 at 13:07 UTC