diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-06-05 11:06:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-05 11:06:16 -0700 |
commit | c0389c3c7a77187c36ebeffc63bc5e6e43a0d11a (patch) | |
tree | c37bbd5c42b6138cf723eef74cf4b4732b94ff82 /bindgen-integration/cpp/Test.h | |
parent | 8a0934763ead0e911b24bf685d052e79aeda5f95 (diff) | |
parent | 10106aa8a40f36477fdc9cd034d9a2eec2698318 (diff) |
Auto merge of #736 - emilio:bitfields-revamp, r=fitzgen
ir: Fix a bunch of bitfield correctness issues.
In particular, the "flush the allocation unit" logic is only valid for
ms_structs (that is, MSVC).
It's slightly annoying to have this different behavior, but it'd work just fine
if we'd turn that on for MSVC.
This patch doesn't do that, yet at least, and adds tests for all the weird
bitfield alignments around.
Fixes #726 (and another set of hidden issues by the old code).
Diffstat (limited to 'bindgen-integration/cpp/Test.h')
-rw-r--r-- | bindgen-integration/cpp/Test.h | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index 01c7aea1..4b8c1690 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -49,7 +49,7 @@ struct Second { }; enum ItemKind { - ITEM_KIND_UNO, + ITEM_KIND_UNO = 0, ITEM_KIND_DOS, ITEM_KIND_TRES, }; @@ -63,6 +63,35 @@ struct Third { bool assert(int first, bool second, ItemKind third); }; +enum MyEnum { + ONE = 0, + TWO, + THREE, + FOUR, +}; + +struct Fourth { + MyEnum tag: 2; + unsigned long ptr: 48; + + /// Returns true if the bitfields match the arguments, false otherwise. + bool assert(MyEnum tag, unsigned long ptr); +}; + +struct Date2 { + unsigned short nWeekDay : 3; // 0..7 (3 bits) + unsigned short nMonthDay : 6; // 0..31 (6 bits) + unsigned short nMonth : 5; // 0..12 (5 bits) + unsigned short nYear : 8; // 0..100 (8 bits) + unsigned char byte : 8; + + bool assert(unsigned short nWeekDay, + unsigned short nMonthDay, + unsigned short nMonth, + unsigned short nYear, + unsigned short byte); +}; + } // namespace bitfields struct AutoRestoreBool { |