Skip to content

Pointer to va_list is translated wrong #1440

@Rua

Description

@Rua

When the va_list type appears by value in a function parameter, c2rust translates it as a Rust VaList. That's correct. But when a function takes va_list * by pointer, then that gets translated as Rust *mut VaList, which is not correct. To see why, consider what such a pointer actually points to on architectures that use a dedicated struct type for va_list, such as x86-64 or Linux aarch64:

  • In C, va_list is a struct or array containing a struct. A pointer va_list * is thus a pointer to this struct or array. Dereferencing the pointer gives you the struct.
  • In Rust, VaList does not contain the struct, which is in VaListImpl. VaList only contains a reference to the struct. Thus, dereferencing *mut VaList gives you the VaList, which is not the struct but that reference. You need to dereference VaList again to get the struct inside VaListImpl.

Clearly, these two are not equivalent and therefore not ABI compatible. The correct translation would be to use VaListImpl normally, but VaList if and only if C passes va_list by value. va_list * by pointer should always be translated to *mut VaListImpl.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions