diff --git a/csmith-fuzzing/predicate.py b/csmith-fuzzing/predicate.py index 2f561148e9..3bf452ef19 100755 --- a/csmith-fuzzing/predicate.py +++ b/csmith-fuzzing/predicate.py @@ -45,6 +45,11 @@ default=BINDGEN_ARGS, help="An argument string that `bindgen` should be invoked with. By default, all traits are derived. Note that the input header and output bindings file will automatically be provided by this script, and you should not manually specify them.") +parser.add_argument( + "--save-temp-files", + action="store_true", + help="Do not delete temporary files.") + parser.add_argument( "input", type=str, @@ -144,11 +149,12 @@ def main(): exit_code = 2 print("Unexpected exception:", e) - for path in TEMP_FILES: - try: - os.remove(path) - except Exception as e: - print("Unexpected exception:", e) + if not args.save_temp_files: + for path in TEMP_FILES: + try: + os.remove(path) + except Exception as e: + print("Unexpected exception:", e) sys.exit(exit_code) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index db8fc4ddba..b8893f9c41 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2148,7 +2148,10 @@ impl EnumVariation { /// A helper type to construct different enum variations. enum EnumBuilder<'a> { - Rust(quote::Tokens), + Rust { + tokens: quote::Tokens, + emitted_any_variants: bool, + }, Bitfield { canonical_name: &'a str, tokens: quote::Tokens, @@ -2188,7 +2191,10 @@ impl<'a> EnumBuilder<'a> { pub enum #ident }; tokens.append("{"); - EnumBuilder::Rust(tokens) + EnumBuilder::Rust { + tokens, + emitted_any_variants: false, + } } EnumVariation::Consts => { @@ -2229,12 +2235,15 @@ impl<'a> EnumBuilder<'a> { }; match self { - EnumBuilder::Rust(tokens) => { + EnumBuilder::Rust { tokens, emitted_any_variants: _ } => { let name = ctx.rust_ident(variant_name); - EnumBuilder::Rust(quote! { - #tokens - #name = #expr, - }) + EnumBuilder::Rust { + tokens: quote! { + #tokens + #name = #expr, + }, + emitted_any_variants: true, + } } EnumBuilder::Bitfield { .. } => { @@ -2295,9 +2304,12 @@ impl<'a> EnumBuilder<'a> { result: &mut CodegenResult<'b>, ) -> quote::Tokens { match self { - EnumBuilder::Rust(mut t) => { - t.append("}"); - t + EnumBuilder::Rust { mut tokens, emitted_any_variants } => { + if !emitted_any_variants { + tokens.append(quote! { __bindgen_cannot_repr_c_on_empty_enum = 0 }); + } + tokens.append("}"); + tokens } EnumBuilder::Bitfield { canonical_name, @@ -2432,15 +2444,12 @@ impl CodeGenerator for Enum { let mut attrs = vec![]; - // FIXME: Rust forbids repr with empty enums. Remove this condition when - // this is allowed. - // // TODO(emilio): Delegate this to the builders? if variation.is_rust() { - if !self.variants().is_empty() { - attrs.push(attributes::repr(repr_name)); - } - } else if variation.is_bitfield() { + attrs.push(attributes::repr(repr_name)); + } + + if variation.is_bitfield() || variation.is_rust() { attrs.push(attributes::repr("C")); } diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs index 718905d9bb..c482530c87 100644 --- a/tests/expectations/tests/anon_enum.rs +++ b/tests/expectations/tests/anon_enum.rs @@ -12,6 +12,7 @@ pub struct Test { } pub const Test_T_NONE: Test__bindgen_ty_1 = Test__bindgen_ty_1::T_NONE; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Test__bindgen_ty_1 { T_NONE = 0, @@ -40,6 +41,7 @@ fn bindgen_test_layout_Test() { ); } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Baz { Foo = 0, diff --git a/tests/expectations/tests/anon_enum_trait.rs b/tests/expectations/tests/anon_enum_trait.rs index 9f5a6c56f1..21d2287944 100644 --- a/tests/expectations/tests/anon_enum_trait.rs +++ b/tests/expectations/tests/anon_enum_trait.rs @@ -19,6 +19,7 @@ pub const DataType_channels: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::ge pub const DataType_fmt: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; pub const DataType_type_: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum DataType__bindgen_ty_1 { generic_type = 0, @@ -31,6 +32,7 @@ pub struct Foo { pub const Foo_Bar: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo__bindgen_ty_1 { Bar = 0, diff --git a/tests/expectations/tests/anon_enum_whitelist.rs b/tests/expectations/tests/anon_enum_whitelist.rs index c639410f9a..45b858fdea 100644 --- a/tests/expectations/tests/anon_enum_whitelist.rs +++ b/tests/expectations/tests/anon_enum_whitelist.rs @@ -7,6 +7,7 @@ pub const NODE_FLAG_FOO: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_FOO; pub const NODE_FLAG_BAR: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_BAR; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { NODE_FLAG_FOO = 0, diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index fdf01a7a5d..da990ae9aa 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -14,6 +14,7 @@ pub struct TErrorResult { pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum TErrorResult_UnionState { HasMessage = 0, diff --git a/tests/expectations/tests/anon_union_1_0.rs b/tests/expectations/tests/anon_union_1_0.rs index 8d19c9fc3d..67a332c01c 100644 --- a/tests/expectations/tests/anon_union_1_0.rs +++ b/tests/expectations/tests/anon_union_1_0.rs @@ -58,6 +58,7 @@ pub struct TErrorResult { pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum TErrorResult_UnionState { HasMessage = 0, diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs index 6f4a0f693e..5174d1aabc 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -84,6 +84,7 @@ where } } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum MyEnum { ONE = 0, diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index ecdbdf9fd6..f656012584 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -214,6 +214,7 @@ fn bindgen_test_layout_B() { ); } #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum StepSyntax { Keyword = 0, diff --git a/tests/expectations/tests/class_with_inner_struct_1_0.rs b/tests/expectations/tests/class_with_inner_struct_1_0.rs index 1236950ccd..e807236232 100644 --- a/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -272,6 +272,7 @@ impl Clone for B { } } #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum StepSyntax { Keyword = 0, diff --git a/tests/expectations/tests/const_enum_unnamed.rs b/tests/expectations/tests/const_enum_unnamed.rs index 539c8916c6..833f835172 100644 --- a/tests/expectations/tests/const_enum_unnamed.rs +++ b/tests/expectations/tests/const_enum_unnamed.rs @@ -7,6 +7,7 @@ pub const FOO_BAR: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAR; pub const FOO_BAZ: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAZ; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { FOO_BAR = 0, @@ -19,6 +20,7 @@ pub struct Foo { } pub const Foo_FOO_BAR: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::FOO_BAR; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo__bindgen_ty_1 { FOO_BAR = 10, diff --git a/tests/expectations/tests/constify-enum.rs b/tests/expectations/tests/constify-enum.rs index 78644ae4d5..79fc4dff31 100644 --- a/tests/expectations/tests/constify-enum.rs +++ b/tests/expectations/tests/constify-enum.rs @@ -9,6 +9,7 @@ pub const nsCSSPropertyID_eCSSProperty_COUNT_unexistingVariantValue: nsCSSProper pub const nsCSSPropertyID_eCSSProperty_COUNT: nsCSSPropertyID = nsCSSPropertyID::eCSSPropertyAlias_aa; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum nsCSSPropertyID { eCSSProperty_a = 0, diff --git a/tests/expectations/tests/empty-enum.rs b/tests/expectations/tests/empty-enum.rs new file mode 100644 index 0000000000..4ec7df8a63 --- /dev/null +++ b/tests/expectations/tests/empty-enum.rs @@ -0,0 +1,36 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +pub type EmptyConstified = ::std::os::raw::c_uint; +#[repr(u32)] +#[repr(C)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum EmptyRustified { + __bindgen_cannot_repr_c_on_empty_enum = 0, +} +pub mod EmptyModule { + pub type Type = ::std::os::raw::c_uint; +} +#[repr(i8)] +#[repr(C)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum EmptyClassRustified { + __bindgen_cannot_repr_c_on_empty_enum = 0, +} +pub type EmptyClassConstified = ::std::os::raw::c_char; +pub mod EmptyClassModule { + pub type Type = ::std::os::raw::c_char; +} +#[repr(i8)] +#[repr(C)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum ForwardClassRustified { + __bindgen_cannot_repr_c_on_empty_enum = 0, +} +pub type ForwardClassConstified = ::std::os::raw::c_char; +pub mod ForwardClassModule { + pub type Type = ::std::os::raw::c_char; +} diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index 70c308307f..b1920aaef0 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -5,12 +5,14 @@ #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { Bar = 0, Qux = 1, } #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Neg { MinusOne = -1, diff --git a/tests/expectations/tests/enum_alias.rs b/tests/expectations/tests/enum_alias.rs index f12c08d347..cde429f762 100644 --- a/tests/expectations/tests/enum_alias.rs +++ b/tests/expectations/tests/enum_alias.rs @@ -5,6 +5,7 @@ #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Bar { VAL = 0, diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index e9e6f13cc6..42ee383214 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -7,6 +7,7 @@ pub const match_: _bindgen_ty_1 = _bindgen_ty_1::match_; pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { match_ = 0, diff --git a/tests/expectations/tests/enum_dupe.rs b/tests/expectations/tests/enum_dupe.rs index a91999ed2b..151b2cd027 100644 --- a/tests/expectations/tests/enum_dupe.rs +++ b/tests/expectations/tests/enum_dupe.rs @@ -6,6 +6,7 @@ pub const Foo_Dupe: Foo = Foo::Bar; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { Bar = 1, diff --git a/tests/expectations/tests/enum_explicit_type.rs b/tests/expectations/tests/enum_explicit_type.rs index 7ff0ef51e4..644a1cea41 100644 --- a/tests/expectations/tests/enum_explicit_type.rs +++ b/tests/expectations/tests/enum_explicit_type.rs @@ -5,34 +5,40 @@ #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { Bar = 0, Qux = 1, } #[repr(i8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Neg { MinusOne = -1, One = 1, } #[repr(u16)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Bigger { Much = 255, Larger = 256, } #[repr(i64)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum MuchLong { MuchLow = -4294967296, } #[repr(i64)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum MuchLongLong { I64_MIN = -9223372036854775808, } #[repr(u64)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum MuchULongLong { MuchHigh = 4294967296, diff --git a/tests/expectations/tests/enum_in_template_with_typedef.rs b/tests/expectations/tests/enum_in_template_with_typedef.rs index 06dea12630..588bb42b9e 100644 --- a/tests/expectations/tests/enum_in_template_with_typedef.rs +++ b/tests/expectations/tests/enum_in_template_with_typedef.rs @@ -13,6 +13,7 @@ pub type std_fbstring_core_category_type = u8; pub const std_fbstring_core_Category_Bar: std_fbstring_core_Category = std_fbstring_core_Category::Foo; #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum std_fbstring_core_Category { Foo = 0, diff --git a/tests/expectations/tests/enum_negative.rs b/tests/expectations/tests/enum_negative.rs index 100f27db2e..1fe2f6a4ba 100644 --- a/tests/expectations/tests/enum_negative.rs +++ b/tests/expectations/tests/enum_negative.rs @@ -5,6 +5,7 @@ #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { Bar = -2, diff --git a/tests/expectations/tests/enum_packed.rs b/tests/expectations/tests/enum_packed.rs index cc85b55326..d8e96b0ffb 100644 --- a/tests/expectations/tests/enum_packed.rs +++ b/tests/expectations/tests/enum_packed.rs @@ -5,18 +5,21 @@ #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { Bar = 0, Qux = 1, } #[repr(i8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Neg { MinusOne = -1, One = 1, } #[repr(u16)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Bigger { Much = 255, diff --git a/tests/expectations/tests/forward-enum-decl.rs b/tests/expectations/tests/forward-enum-decl.rs index 5502c4c4f8..c2dea97aeb 100644 --- a/tests/expectations/tests/forward-enum-decl.rs +++ b/tests/expectations/tests/forward-enum-decl.rs @@ -5,6 +5,7 @@ #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum CSSPseudoClassType { empty = 0, diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index 290a148c0e..33d908e20e 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -4,8 +4,12 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum baz {} +pub enum baz { + __bindgen_cannot_repr_c_on_empty_enum = 0, +} #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo { diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index b2949da362..f9040a9982 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -77,6 +77,7 @@ pub mod root { } } #[repr(u32)] + #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum n { o = 0, diff --git a/tests/expectations/tests/issue-410.rs b/tests/expectations/tests/issue-410.rs index 928701ef18..f23462bf6c 100644 --- a/tests/expectations/tests/issue-410.rs +++ b/tests/expectations/tests/issue-410.rs @@ -40,6 +40,10 @@ pub mod root { } } } + #[repr(u32)] + #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] - pub enum JSWhyMagic {} + pub enum JSWhyMagic { + __bindgen_cannot_repr_c_on_empty_enum = 0, + } } diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index 8975938d40..d338e30cf3 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -70,6 +70,7 @@ impl Default for basic_string___long { pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum basic_string__bindgen_ty_1 { __min_cap = 0, @@ -109,6 +110,7 @@ impl Default for basic_string___ulx { pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum basic_string__bindgen_ty_2 { __n_words = 0, diff --git a/tests/expectations/tests/issue-493_1_0.rs b/tests/expectations/tests/issue-493_1_0.rs index da6dac7700..4dfc26d8d6 100644 --- a/tests/expectations/tests/issue-493_1_0.rs +++ b/tests/expectations/tests/issue-493_1_0.rs @@ -70,6 +70,7 @@ impl Default for basic_string___long { pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum basic_string__bindgen_ty_1 { __min_cap = 0, @@ -107,6 +108,7 @@ impl Default for basic_string___ulx { pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum basic_string__bindgen_ty_2 { __n_words = 0, diff --git a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index b2ddf7138c..3029a67032 100644 --- a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -7,6 +7,7 @@ pub const ENUM_VARIANT_1: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_1; pub const ENUM_VARIANT_2: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_2; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { ENUM_VARIANT_1 = 0, diff --git a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/tests/expectations/tests/issue-888-enum-var-decl-jump.rs index 61cbfc3a48..c0ac112d18 100644 --- a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs +++ b/tests/expectations/tests/issue-888-enum-var-decl-jump.rs @@ -34,6 +34,10 @@ pub mod root { ); } } + #[repr(u32)] + #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] - pub enum a {} + pub enum a { + __bindgen_cannot_repr_c_on_empty_enum = 0, + } } diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 80526b3e79..2b2d0d77f9 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -87,6 +87,7 @@ pub const JSVAL_TAG_SHIFT: ::std::os::raw::c_uint = 47; pub const JSVAL_PAYLOAD_MASK: ::std::os::raw::c_ulonglong = 140737488355327; pub const JSVAL_TAG_MASK: ::std::os::raw::c_longlong = -140737488355328; #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSValueType { JSVAL_TYPE_DOUBLE = 0, @@ -102,6 +103,7 @@ pub enum JSValueType { JSVAL_TYPE_MISSING = 33, } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSValueTag { JSVAL_TAG_MAX_DOUBLE = 131056, @@ -115,6 +117,7 @@ pub enum JSValueTag { JSVAL_TAG_OBJECT = 131064, } #[repr(u64)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_MAX_DOUBLE = 18444492278190833663, @@ -128,6 +131,7 @@ pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSWhyMagic { JS_ELEMENTS_HOLE = 0, diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index cac9b0b8e2..ab11a23165 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -130,6 +130,7 @@ pub const JSVAL_TAG_SHIFT: ::std::os::raw::c_uint = 47; pub const JSVAL_PAYLOAD_MASK: ::std::os::raw::c_ulonglong = 140737488355327; pub const JSVAL_TAG_MASK: ::std::os::raw::c_longlong = -140737488355328; #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSValueType { JSVAL_TYPE_DOUBLE = 0, @@ -145,6 +146,7 @@ pub enum JSValueType { JSVAL_TYPE_MISSING = 33, } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSValueTag { JSVAL_TAG_MAX_DOUBLE = 131056, @@ -158,6 +160,7 @@ pub enum JSValueTag { JSVAL_TAG_OBJECT = 131064, } #[repr(u64)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_MAX_DOUBLE = 18444492278190833663, @@ -171,6 +174,7 @@ pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSWhyMagic { JS_ELEMENTS_HOLE = 0, diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index b767757376..59884451b8 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -11,6 +11,7 @@ pub const IP_FIRST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_FIRST_FRAG_IDX; pub const IP_MIN_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MIN_FRAG_NUM; pub const IP_MAX_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MAX_FRAG_NUM; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { IP_LAST_FRAG_IDX = 0, diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index 9115741670..2cde7c42cf 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -83,8 +83,7 @@ pub struct cmdline_token_ops { >, /// return the num of possible choices for this token pub complete_get_nb: ::std::option::Option< - unsafe extern "C" fn(arg1: *mut cmdline_parse_token_hdr_t) - -> ::std::os::raw::c_int, + unsafe extern "C" fn(arg1: *mut cmdline_parse_token_hdr_t) -> ::std::os::raw::c_int, >, /// return the elt x for this token (token, idx, dstbuf, size) pub complete_get_elt: ::std::option::Option< @@ -167,6 +166,7 @@ impl Default for cmdline_token_ops { } } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum cmdline_numtype { UINT8 = 0, diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 9721fb7b32..599f9788fe 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -116,6 +116,7 @@ pub const RTE_ETH_FLOW_GENEVE: ::std::os::raw::c_uint = 20; pub const RTE_ETH_FLOW_NVGRE: ::std::os::raw::c_uint = 21; pub const RTE_ETH_FLOW_MAX: ::std::os::raw::c_uint = 22; #[repr(u32)] +#[repr(C)] /// A set of values to identify what method is to be used to route /// packets to multiple queues. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -343,6 +344,7 @@ impl rte_eth_rxmode { } } #[repr(u32)] +#[repr(C)] /// A set of values to identify what method is to be used to transmit /// packets using multi-TCs. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -532,6 +534,7 @@ impl Default for rte_eth_rss_conf { } } #[repr(u32)] +#[repr(C)] /// This enum indicates the possible number of traffic classes /// in DCB configratioins #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -540,6 +543,7 @@ pub enum rte_eth_nb_tcs { ETH_8_TCS = 8, } #[repr(u32)] +#[repr(C)] /// This enum indicates the possible number of queue pools /// in VMDQ configurations. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -1054,6 +1058,7 @@ impl Default for rte_eth_vmdq_rx_conf { } } #[repr(u32)] +#[repr(C)] /// Flow Director setting modes: none, signature or perfect. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_mode { @@ -1064,6 +1069,7 @@ pub enum rte_fdir_mode { RTE_FDIR_MODE_PERFECT_TUNNEL = 4, } #[repr(u32)] +#[repr(C)] /// Memory space that can be configured to store Flow Director filters /// in the board memory. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -1073,6 +1079,7 @@ pub enum rte_fdir_pballoc_type { RTE_FDIR_PBALLOC_256K = 2, } #[repr(u32)] +#[repr(C)] /// Select report mode of FDIR hash information in RX descriptors. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_status_mode { @@ -1366,6 +1373,7 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); } #[repr(u32)] +#[repr(C)] /// Payload type #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_payload_type { diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index ad37574d9c..532fcae8e1 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -159,6 +159,7 @@ pub const RTE_ETH_FLOW_GENEVE: ::std::os::raw::c_uint = 20; pub const RTE_ETH_FLOW_NVGRE: ::std::os::raw::c_uint = 21; pub const RTE_ETH_FLOW_MAX: ::std::os::raw::c_uint = 22; #[repr(u32)] +#[repr(C)] /// A set of values to identify what method is to be used to route /// packets to multiple queues. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -391,6 +392,7 @@ impl rte_eth_rxmode { } } #[repr(u32)] +#[repr(C)] /// A set of values to identify what method is to be used to transmit /// packets using multi-TCs. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -590,6 +592,7 @@ impl Default for rte_eth_rss_conf { } } #[repr(u32)] +#[repr(C)] /// This enum indicates the possible number of traffic classes /// in DCB configratioins #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -598,6 +601,7 @@ pub enum rte_eth_nb_tcs { ETH_8_TCS = 8, } #[repr(u32)] +#[repr(C)] /// This enum indicates the possible number of queue pools /// in VMDQ configurations. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -1152,6 +1156,7 @@ impl Default for rte_eth_vmdq_rx_conf { } } #[repr(u32)] +#[repr(C)] /// Flow Director setting modes: none, signature or perfect. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_mode { @@ -1162,6 +1167,7 @@ pub enum rte_fdir_mode { RTE_FDIR_MODE_PERFECT_TUNNEL = 4, } #[repr(u32)] +#[repr(C)] /// Memory space that can be configured to store Flow Director filters /// in the board memory. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -1171,6 +1177,7 @@ pub enum rte_fdir_pballoc_type { RTE_FDIR_PBALLOC_256K = 2, } #[repr(u32)] +#[repr(C)] /// Select report mode of FDIR hash information in RX descriptors. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_status_mode { @@ -1479,6 +1486,7 @@ impl Clone for rte_eth_fdir_masks { } } #[repr(u32)] +#[repr(C)] /// Payload type #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_payload_type { diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index 21f8454677..501e1bcec7 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -48,6 +48,7 @@ pub const IP_FIRST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_FIRST_FRAG_IDX; pub const IP_MIN_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MIN_FRAG_NUM; pub const IP_MAX_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MAX_FRAG_NUM; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { IP_LAST_FRAG_IDX = 0, diff --git a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs index 8faddfe969..1b6aca15b5 100644 --- a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs @@ -7,6 +7,7 @@ pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { foo = 4, bar = 8, } pub type EasyToOverflow = ::std::os::raw::c_ulonglong; diff --git a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs index 096bc1822f..76cbf24edf 100644 --- a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs @@ -7,6 +7,7 @@ pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { foo = 4, diff --git a/tests/expectations/tests/libclang-4/constant-evaluate.rs b/tests/expectations/tests/libclang-4/constant-evaluate.rs index 096bc1822f..76cbf24edf 100644 --- a/tests/expectations/tests/libclang-4/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-4/constant-evaluate.rs @@ -7,6 +7,7 @@ pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { foo = 4, diff --git a/tests/expectations/tests/nsStyleAutoArray.rs b/tests/expectations/tests/nsStyleAutoArray.rs index 0c9f1ec618..199222ecb7 100644 --- a/tests/expectations/tests/nsStyleAutoArray.rs +++ b/tests/expectations/tests/nsStyleAutoArray.rs @@ -23,6 +23,7 @@ pub struct nsStyleAutoArray { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum nsStyleAutoArray_WithSingleInitialElement { WITH_SINGLE_INITIAL_ELEMENT = 0, diff --git a/tests/expectations/tests/overflowed_enum.rs b/tests/expectations/tests/overflowed_enum.rs index 0e8700dc56..9104867d52 100644 --- a/tests/expectations/tests/overflowed_enum.rs +++ b/tests/expectations/tests/overflowed_enum.rs @@ -5,6 +5,7 @@ #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { BAP_ARM = 9698489, @@ -12,6 +13,7 @@ pub enum Foo { BAP_X86_64 = 3128633167, } #[repr(u16)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Bar { One = 1, diff --git a/tests/expectations/tests/prepend-enum-constified-variant.rs b/tests/expectations/tests/prepend-enum-constified-variant.rs index df9ecf3cda..afe2c0b1f8 100644 --- a/tests/expectations/tests/prepend-enum-constified-variant.rs +++ b/tests/expectations/tests/prepend-enum-constified-variant.rs @@ -6,6 +6,7 @@ pub const AV_CODEC_ID_TTF: AVCodecID = AVCodecID::AV_CODEC_ID_FIRST_UNKNOWN; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum AVCodecID { AV_CODEC_ID_FIRST_UNKNOWN = 98304, diff --git a/tests/expectations/tests/short-enums.rs b/tests/expectations/tests/short-enums.rs index c3b26da93a..882b368c63 100644 --- a/tests/expectations/tests/short-enums.rs +++ b/tests/expectations/tests/short-enums.rs @@ -5,16 +5,19 @@ #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum one_byte_t { SOME_VALUE = 1, } #[repr(u16)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum two_byte_t { SOME_OTHER_VALUE = 256, } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum four_byte_t { SOME_BIGGER_VALUE = 16777216, diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs index d153aa0887..0e6151441e 100644 --- a/tests/expectations/tests/struct_typedef.rs +++ b/tests/expectations/tests/struct_typedef.rs @@ -68,12 +68,14 @@ impl Default for _bindgen_ty_1 { pub type struct_ptr_t = *mut _bindgen_ty_1; pub type struct_ptr_ptr_t = *mut *mut _bindgen_ty_1; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum typedef_named_enum { ENUM_HAS_NAME = 1, } pub const ENUM_IS_ANON: _bindgen_ty_2 = _bindgen_ty_2::ENUM_IS_ANON; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_2 { ENUM_IS_ANON = 0, diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index 42dfbb529a..cbbdaa7b91 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -40,6 +40,7 @@ pub mod root { ); } #[repr(u32)] + #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum typedef_enum { BAR = 1, @@ -80,6 +81,7 @@ pub mod root { pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; #[repr(u32)] + #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_2 { BAR = 1, diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index 6a4d0589e6..22cd8ea5ac 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -84,6 +84,7 @@ where } } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum nsStyleSVGOpacitySource { eStyleSVGOpacitySource_Normal = 0, diff --git a/tests/headers/empty-enum.h b/tests/headers/empty-enum.h new file mode 100644 index 0000000000..8b7502e671 --- /dev/null +++ b/tests/headers/empty-enum.h @@ -0,0 +1,15 @@ +// bindgen-flags: --rustified-enum '.*Rustified.*' --constified-enum-module '.*Module.*' -- -x c++ --std=c++14 + +// Constified is default, so no flag for that. + +enum EmptyConstified {}; +enum EmptyRustified {}; +enum EmptyModule {}; + +enum class EmptyClassRustified : char {}; +enum class EmptyClassConstified : char {}; +enum class EmptyClassModule : char {}; + +enum class ForwardClassRustified : char; +enum class ForwardClassConstified : char; +enum class ForwardClassModule : char;