Skip to content

Commit

Permalink
Add a repr(packed(N)) test
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Jun 30, 2019
1 parent 082975c commit 2460886
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Automated tests of FFI bindings.
"""

[dependencies]
syntex_syntax = "0.59.1"
syntex_syntax2 = "0.0.1"
cc = "1.0.1"
rustc_version = "0.2"

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#![deny(missing_docs)]

extern crate cc;
extern crate syntex_syntax as syntax;
extern crate syntex_syntax2 as syntax;

extern crate rustc_version;

Expand Down Expand Up @@ -2052,7 +2052,7 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
let is_c = i.attrs.iter().any(|a| {
attr::find_repr_attrs(self.sh, a)
.iter()
.any(|a| *a == ReprAttr::ReprExtern)
.any(|a| *a == ReprAttr::ReprExtern /*|| *a == ReprAttr::ReprTransparent*/)
});
if !is_c && !(self.opts.skip_struct)(&i.ident.to_string()) {
panic!("{} is not marked #[repr(C)]", i.ident);
Expand Down
1 change: 0 additions & 1 deletion testcrate/src/t1.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ unsigned T1static = 3;
const uint8_t T1_static_u8 = 42;
uint8_t T1_static_mut_u8 = 37;


uint8_t foo(uint8_t a, uint8_t b) { return a + b; }
void bar(uint8_t a) { return; }
void baz(void) { return; }
Expand Down
9 changes: 9 additions & 0 deletions testcrate/src/t1.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ struct Pack {

# pragma pack(pop)

# pragma pack(push,2)

struct Pack2 {
uint8_t a;
uint32_t b;
};

# pragma pack(pop)

// volatile pointers in struct fields:
struct V {
volatile uint8_t* v;
Expand Down
9 changes: 9 additions & 0 deletions testcrate/src/t1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub struct T1StructWithUnion {
pub u: T1NoTypedefUnion,
}

// #[repr(transparent)]
// pub struct Transparent(i32);

pub type T1TypedefDouble = c_double;
pub type T1TypedefPtr = *mut c_int;
pub type T1TypedefStruct = T1Bar;
Expand Down Expand Up @@ -156,6 +159,12 @@ pub struct Pack {
pub b: u16,
}

#[repr(C, packed(2))]
pub struct Pack2 {
pub a: u8,
pub b: u32,
}

#[repr(C)]
pub struct V {
pub v: *mut u8,
Expand Down

0 comments on commit 2460886

Please sign in to comment.