Skip to content

bitfield_align_2.rs test fails to build on Windows #1009

Open
@AndrewGaspar

Description

@AndrewGaspar

cargo test under tests\expectations fails today when building bitfield_align_2.rs.

Error message:

C:\Users\andre\Projects\rust-bindgen\tests\expectations [master ≡]> cargo test
   Compiling tests_expectations v0.1.0 (file:///C:/Users/andre/Projects/rust-bindgen/tests/expectations)
error[E0512]: transmute called with differently sized types: u64 (64 bits) to i32 (32 bits)
  --> tests\bitfield_align_2.rs:93:18
   |
93 |         unsafe { ::std::mem::transmute(val as u64) }
   |                  ^^^^^^^^^^^^^^^^^^^^^ transmuting between 64 bits and 32 bits

error: aborting due to previous error(s)

error: Could not compile `tests_expectations`.
Build failed, waiting for other jobs to finish...
error: build failed

This is the function being built:

#[inline]
    pub fn ptr(&self) -> ::std::os::raw::c_long {
        let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
        unsafe {
            ::std::ptr::copy_nonoverlapping(
                &self._bitfield_1 as *const _ as *const u8,
                &mut unit_field_val as *mut u64 as *mut u8,
                ::std::mem::size_of::<u64>(),
            )
        };
        let mask = 18446744073709551612u64 as u64;
        let val = (unit_field_val & mask) >> 2usize;
        unsafe { ::std::mem::transmute(val as u64) }
    }

The problem is that on Windows c_long is 32-bits, whereas on all other platforms (as defined by Rust), it is 64-bits. We need to somehow change the as operator to narrow the type to the size of the platform representation of the type.

The file being translated is bitfield_align_2.h

// bindgen-flags: --rustified-enum .*
enum MyEnum {
    ONE,
    TWO,
    THREE,
    FOUR
};

struct TaggedPtr {
    enum MyEnum tag : 2;
    long   ptr : 62;
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions