Skip to content

Commit

Permalink
Add support for packed structs
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Nov 27, 2018
1 parent 7ca0182 commit 3e2ac3a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ impl TestGenerator {
.flag("-Werror")
.flag("-Wno-unused-parameter")
.flag("-Wno-type-limits")
// allow taking address of packed struct members:
.flag("-Wno-address-of-packed-member")
.flag("-Wno-deprecated-declarations"); // allow deprecated items
}

Expand Down
27 changes: 27 additions & 0 deletions testcrate/src/t1.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,37 @@ struct Q {
uint8_t q2;
};


struct T1_conflict_foo {
int a;
};

struct T1_conflict{
int foo;
};

// test packed structs
//
// on msvc there is only pragma pack
// on clang and gcc there is a packed attribute

#ifdef _MSC_VER
#pragma pack(push,1)
#endif

#ifndef _MSC_VER
#define PACK __attribute__((packed))
#else
#define PACK
#endif

struct Pack {
uint8_t a;
uint16_t b;
} PACK;

#undef PACK

#ifdef _MSC_VER
#pragma pack(pop)
#endif
6 changes: 6 additions & 0 deletions testcrate/src/t1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,9 @@ pub struct T1_conflict_foo {
pub struct T1_conflict {
pub foo: i32,
}

#[repr(C, packed)]
pub struct Pack {
pub a: u8,
pub b: u16,
}

0 comments on commit 3e2ac3a

Please sign in to comment.