Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Conversation

@GreyElaina
Copy link

Basically copied from https://github.com/mahkoh/repr-c/tree/master/repc/impl/src/builder.

Required to build a cross-verifier to fit existing behavior.

@Vexu
Copy link
Member

Vexu commented Jul 15, 2025

C structs cannot be translated as packed structs, instead bitfields that are part of the same host byte should be translated as a packed struct that is part of the larger struct:

struct S {
    int arr[4];
    int a: 12;
    int b: 12;
    int :0;
    int c: 12;
};
pub const struct_S = extern struct {
    arr: [4]c_int = @import("std").mem.zeroes([4]c_int),
    bitfield: packed struct(c_int) {
        a: i12 = 0,
        b: i12 = 0,
        _pad: u8 = 0,
    } = .{},
    bitfield1: packed struct(c_int) {
        c: i12 = 0,
        _pad: u20 = 0,
    } = .{},
};

@GreyElaina
Copy link
Author

GreyElaina commented Jul 15, 2025

Even just the work of creating documentation for what the C ABI for bit fields is for the various compilers would be 60%+ of the work of solving this issue.

So is it. Any helpful reference could we have? or more testcases.

@GreyElaina
Copy link
Author

ok i'm stupid, arocc already ship it.

@steeve
Copy link
Contributor

steeve commented Nov 25, 2025

@GreyElaina incredible work, what is the status of that draft PR ?
For context, we use DPDK heavily and it relies a lot on bitfields. Even ignoring them instead of turning the whole struct opaque would go a long way (at least for us)

@GreyElaina
Copy link
Author

@GreyElaina incredible work, what is the status of that draft PR ? For context, we use DPDK heavily and it relies a lot on bitfields. Even ignoring them instead of turning the whole struct opaque would go a long way (at least for us)

eh, i just borrowed these values from arocc itself. it's hard (and too busy for me) to write a comprehensive verifier to, at least, fuzz test it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants