From 9c59ac9ceb04a40b4b7a57397791fe334fb513ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 13 Jan 2024 01:29:52 +0100 Subject: [PATCH] ci: Remove llvm 5, introduce llvm 16 LLVM 5 is ancient. --- .github/workflows/bindgen.yml | 19 +- CONTRIBUTING.md | 8 +- appveyor.yml | 12 +- bindgen-cli/Cargo.toml | 2 +- bindgen-cli/main.rs | 6 +- bindgen-integration/Cargo.toml | 2 +- bindgen-tests/Cargo.toml | 2 +- bindgen-tests/tests/expectations/build.rs | 2 +- .../{libclang-5 => }/abi_variadic_function.rs | 0 .../tests/{libclang-5 => }/auto.rs | 0 .../tests/{libclang-5 => }/call-conv-field.rs | 0 .../tests/expectations/tests/class.rs | 158 +++++ .../tests/expectations/tests/class_1_0.rs | 158 +++++ .../tests/{libclang-5 => }/const_bool.rs | 0 .../{libclang-5 => }/constant-evaluate.rs | 0 .../tests/constified-enum-module-overflow.rs | 15 +- ...erive-hash-struct-with-incomplete-array.rs | 46 ++ ...0600-cannot-apply-unary-negation-to-u32.rs | 0 .../tests/incomplete-array-padding.rs | 7 + .../tests/issue-544-stylo-creduce-2.rs | 5 +- .../tests/issue-643-inner-struct.rs | 22 + .../issue-769-bad-instantiation-test.rs | 0 .../tests/expectations/tests/layout_align.rs | 32 + .../libclang-5/inline_namespace_nested.rs | 1 - .../tests/libclang-5/issue-2556.rs | 1 - .../tests/libclang-5/objc_template.rs | 57 -- .../libclang-5/ptr32-has-different-size.rs | 41 -- .../tests/libclang-9/abi_variadic_function.rs | 5 - .../expectations/tests/libclang-9/auto.rs | 29 - .../tests/libclang-9/call-conv-field.rs | 50 -- .../expectations/tests/libclang-9/class.rs | 617 ---------------- .../tests/libclang-9/class_1_0.rs | 668 ------------------ .../tests/libclang-9/const_bool.rs | 19 - .../tests/libclang-9/constant-evaluate.rs | 19 - .../constified-enum-module-overflow.rs | 46 ++ ...erive-hash-struct-with-incomplete-array.rs | 154 ---- ...0600-cannot-apply-unary-negation-to-u32.rs | 3 - .../libclang-9/incomplete-array-padding.rs | 180 ----- .../libclang-9/issue-544-stylo-creduce-2.rs | 17 + .../libclang-9/issue-643-inner-struct.rs | 148 ---- .../issue-769-bad-instantiation-test.rs | 60 -- .../tests/libclang-9/layout_align.rs | 291 -------- .../tests/libclang-9/mangling-win32.rs | 46 -- .../tests/libclang-9/objc_inheritance.rs | 107 --- .../partial-specialization-and-inheritance.rs | 33 - .../tests/libclang-9/struct_typedef_ns.rs | 87 +++ .../type_alias_template_specialized.rs | 56 -- .../tests/libclang-9/zero-sized-array.rs | 170 ----- .../tests/{libclang-5 => }/mangling-win32.rs | 0 .../{libclang-5 => }/objc_inheritance.rs | 0 .../tests/{libclang-9 => }/objc_template.rs | 0 .../partial-specialization-and-inheritance.rs | 0 .../expectations/tests/struct_typedef_ns.rs | 21 +- .../type_alias_template_specialized.rs | 0 .../expectations/tests/zero-sized-array.rs | 24 + .../headers/issue-544-stylo-creduce-2.hpp | 7 + bindgen-tests/tests/stylo_sanity.rs | 4 +- bindgen-tests/tests/tests.rs | 16 +- bindgen/Cargo.toml | 2 +- ci/test.sh | 23 +- 60 files changed, 673 insertions(+), 2825 deletions(-) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/abi_variadic_function.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/auto.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/call-conv-field.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/const_bool.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/constant-evaluate.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/error-E0600-cannot-apply-unary-negation-to-u32.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/issue-769-bad-instantiation-test.rs (100%) delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-5/inline_namespace_nested.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-5/ptr32-has-different-size.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/auto.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/class.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs create mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs create mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs create mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/mangling-win32.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/objc_inheritance.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-9 => }/objc_template.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/partial-specialization-and-inheritance.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/type_alias_template_specialized.rs (100%) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 3f85cd862a..883fb46b5c 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -142,7 +142,7 @@ jobs: - debian: null cross: null rust: null - llvm_version: ["5.0", "9.0"] + llvm_version: ["9.0", "16.0"] main_tests: [1] release_build: [0, 1] no_default_features: [0, 1] @@ -155,7 +155,7 @@ jobs: # Test with extra asserts + docs just with latest llvm versions to # prevent explosion - os: ubuntu-latest - llvm_version: "9.0" + llvm_version: "16.0" release_build: 0 no_default_features: 0 feature_extra_asserts: 1 @@ -169,17 +169,20 @@ jobs: # debian: arm64 # cross: aarch64-linux-gnu # rust: aarch64-unknown-linux-gnu - # llvm_version: "9.0" + # llvm_version: "16.0" # main_tests: 0 # release_build: 0 # feature_extra_asserts: 0 # Ensure stuff works on macos too - - os: macos-latest - llvm_version: "9.0" - release_build: 0 - no_default_features: 0 - feature_extra_asserts: 0 + # Disabled for now because llvm doesn't provide releases for x86-64 + # macOS which is what the runner uses. + # + # - os: macos-latest + # llvm_version: "16.0" + # release_build: 0 + # no_default_features: 0 + # feature_extra_asserts: 0 steps: - uses: actions/checkout@v3 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7e5cdc53eb..62cf80742e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -208,8 +208,8 @@ can add multiple test expectations, one for each supported `libclang` version. Instead of having a single `bindgen-tests/tests/expectations/tests/my_test.rs` file, add each of: +* `bindgen-tests/tests/expectations/tests/libclang-16/my_test.rs` * `bindgen-tests/tests/expectations/tests/libclang-9/my_test.rs` -* `bindgen-tests/tests/expectations/tests/libclang-5/my_test.rs` If you need to update the test expectations for a test file that generates different bindings for different `libclang` versions, you *don't* need to have @@ -226,12 +226,6 @@ to check the bindings against with a cargo feature: $ cargo test --features __testing_only_libclang_$VERSION ``` -Where `$VERSION` is one of: - -* `4` -* `3_9` -* `3_8` - depending on which version of `libclang` you have installed. ### Integration Tests diff --git a/appveyor.yml b/appveyor.yml index 973b4cdf07..ffb74eedc6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,18 +2,18 @@ environment: RUST_BACKTRACE: 1 RUST_CHANNEL: "%Configuration%" matrix: - - TARGET: gnu - LLVM_VERSION: 5.0.0-1 - BINDGEN_FEATURES: __testing_only_libclang_5 - TARGET: gnu LLVM_VERSION: 9.0.0-1 BINDGEN_FEATURES: __testing_only_libclang_9 - - TARGET: msvc - LLVM_VERSION: 5.0.0 - BINDGEN_FEATURES: __testing_only_libclang_5 + - TARGET: gnu + LLVM_VERSION: 16.0.4 + BINDGEN_FEATURES: __testing_only_libclang_16 - TARGET: msvc LLVM_VERSION: 9.0.0 BINDGEN_FEATURES: __testing_only_libclang_9 + - TARGET: msvc + LLVM_VERSION: 16.0.4 + BINDGEN_FEATURES: __testing_only_libclang_16 configuration: - stable diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 2738952803..5e04cb0d80 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -40,7 +40,7 @@ which-rustfmt = ["bindgen/which-rustfmt"] # Features used for CI testing __testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] __testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] -__testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] +__testing_only_libclang_16 = ["bindgen/__testing_only_libclang_16"] [package.metadata.release] release = true diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index a3407232de..4b1bfad282 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -13,10 +13,10 @@ use crate::options::builder_from_flags; #[cfg(feature = "logging")] fn clang_version_check() { let version = bindgen::clang_version(); - let expected_version = if cfg!(feature = "__testing_only_libclang_9") { + let expected_version = if cfg!(feature = "__testing_only_libclang_16") { + Some((16, 0)) + } else if cfg!(feature = "__testing_only_libclang_9") { Some((9, 0)) - } else if cfg!(feature = "__testing_only_libclang_5") { - Some((5, 0)) } else { None }; diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index 6c9508ab93..ccdd1467df 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -16,4 +16,4 @@ runtime = ["bindgen/runtime"] __testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] __testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] -__testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] +__testing_only_libclang_16 = ["bindgen/__testing_only_libclang_16"] diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index d3907c3619..1c06c3f10d 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -23,4 +23,4 @@ which-rustfmt = ["bindgen/which-rustfmt"] __testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] __testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] -__testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] +__testing_only_libclang_16 = ["bindgen/__testing_only_libclang_16"] diff --git a/bindgen-tests/tests/expectations/build.rs b/bindgen-tests/tests/expectations/build.rs index 2111185384..6136823e21 100644 --- a/bindgen-tests/tests/expectations/build.rs +++ b/bindgen-tests/tests/expectations/build.rs @@ -8,7 +8,7 @@ use std::fs; use std::io::Write; use std::path::Path; -const LIBCLANG_VERSION_DIRS: &[&str] = &["libclang-5", "libclang-9"]; +const LIBCLANG_VERSION_DIRS: &[&str] = &["libclang-9"]; fn main() { println!("cargo:rerun-if-changed=build.rs"); diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/abi_variadic_function.rs b/bindgen-tests/tests/expectations/tests/abi_variadic_function.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/abi_variadic_function.rs rename to bindgen-tests/tests/expectations/tests/abi_variadic_function.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/auto.rs b/bindgen-tests/tests/expectations/tests/auto.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/auto.rs rename to bindgen-tests/tests/expectations/tests/auto.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/call-conv-field.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs rename to bindgen-tests/tests/expectations/tests/call-conv-field.rs diff --git a/bindgen-tests/tests/expectations/tests/class.rs b/bindgen-tests/tests/expectations/tests/class.rs index ce43204d73..19668a73dd 100644 --- a/bindgen-tests/tests/expectations/tests/class.rs +++ b/bindgen-tests/tests/expectations/tests/class.rs @@ -178,6 +178,8 @@ pub struct C_with_incomplete_array { } #[test] fn bindgen_test_layout_C_with_incomplete_array() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -188,6 +190,36 @@ fn bindgen_test_layout_C_with_incomplete_array() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array), + ), + ); } impl Default for C_with_incomplete_array { fn default() -> Self { @@ -206,6 +238,8 @@ pub struct C_with_incomplete_array_2 { } #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -216,6 +250,26 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array), + ), + ); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -226,6 +280,10 @@ pub struct C_with_zero_length_array_and_incomplete_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { + const UNINIT: ::std::mem::MaybeUninit< + C_with_zero_length_array_and_incomplete_array, + > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -239,6 +297,48 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { stringify!(C_with_zero_length_array_and_incomplete_array), ), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array), + ), + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array), + ), + ); } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { @@ -258,6 +358,10 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { + const UNINIT: ::std::mem::MaybeUninit< + C_with_zero_length_array_and_incomplete_array_2, + > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -271,6 +375,38 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { stringify!(C_with_zero_length_array_and_incomplete_array_2), ), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array), + ), + ); } #[repr(C)] #[derive(Debug, Default, Hash, PartialOrd, Ord, PartialEq, Eq)] @@ -304,6 +440,8 @@ pub struct IncompleteArrayNonCopiable { } #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -314,6 +452,26 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array), + ), + ); } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/class_1_0.rs b/bindgen-tests/tests/expectations/tests/class_1_0.rs index 17cf118242..b6544212cf 100644 --- a/bindgen-tests/tests/expectations/tests/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_1_0.rs @@ -231,6 +231,8 @@ pub struct C_with_incomplete_array { } #[test] fn bindgen_test_layout_C_with_incomplete_array() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -241,6 +243,36 @@ fn bindgen_test_layout_C_with_incomplete_array() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array), + ), + ); } impl Default for C_with_incomplete_array { fn default() -> Self { @@ -259,6 +291,8 @@ pub struct C_with_incomplete_array_2 { } #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -269,6 +303,26 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array), + ), + ); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -279,6 +333,10 @@ pub struct C_with_zero_length_array_and_incomplete_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { + const UNINIT: ::std::mem::MaybeUninit< + C_with_zero_length_array_and_incomplete_array, + > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -292,6 +350,48 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { stringify!(C_with_zero_length_array_and_incomplete_array), ), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array), + ), + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array), + ), + ); } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { @@ -311,6 +411,10 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { + const UNINIT: ::std::mem::MaybeUninit< + C_with_zero_length_array_and_incomplete_array_2, + > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -324,6 +428,38 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { stringify!(C_with_zero_length_array_and_incomplete_array_2), ), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array), + ), + ); } #[repr(C)] #[derive(Debug, Default, Hash, PartialEq, Eq)] @@ -357,6 +493,8 @@ pub struct IncompleteArrayNonCopiable { } #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -367,6 +505,26 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array), + ), + ); } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs b/bindgen-tests/tests/expectations/tests/const_bool.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs rename to bindgen-tests/tests/expectations/tests/const_bool.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs b/bindgen-tests/tests/expectations/tests/constant-evaluate.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs rename to bindgen-tests/tests/expectations/tests/constant-evaluate.rs diff --git a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs index 49498deaa5..61e666d2a0 100644 --- a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs @@ -13,7 +13,7 @@ pub type C_U = B; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { - pub u: u8, + pub u: B, } #[test] fn bindgen_test_layout_A() { @@ -44,3 +44,16 @@ fn __bindgen_test_layout_C_open0_A_close0_instantiation() { concat!("Alignment of template specialization: ", stringify!(C)), ); } +#[test] +fn __bindgen_test_layout_B_open0_A_close0_instantiation() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(B)), + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(B)), + ); +} diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 2a1090e130..d1b4c9004a 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -75,6 +75,8 @@ pub struct test2 { } #[test] fn bindgen_test_layout_test2() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -85,6 +87,21 @@ fn bindgen_test_layout_test2() { 4usize, concat!("Alignment of ", stringify!(test2)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test2), + "::", + stringify!(incomplete_array), + ), + ); } #[repr(C)] #[derive(Debug, Default)] @@ -95,6 +112,8 @@ pub struct test3 { } #[test] fn bindgen_test_layout_test3() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -105,4 +124,31 @@ fn bindgen_test_layout_test3() { 4usize, concat!("Alignment of ", stringify!(test3)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)), + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(incomplete_array), + ), + ); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs b/bindgen-tests/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs rename to bindgen-tests/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index 4a14802d88..c8038e1f40 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -122,6 +122,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -132,6 +134,11 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), + ); } impl Default for foo { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs index 835f029cb2..c81b672956 100644 --- a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs @@ -1,10 +1,11 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] +#[derive(Debug, Copy, Clone)] pub struct Foo { - pub member: Foo_SecondAlias, + pub member: *mut Foo_SecondAlias, } pub type Foo_FirstAlias = [u8; 0usize]; -pub type Foo_SecondAlias = [u8; 0usize]; +pub type Foo_SecondAlias = Foo; impl Default for Foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs index 673221e385..520b3b0ecd 100644 --- a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs @@ -99,6 +99,8 @@ fn bindgen_test_layout_rte_ring_cons() { } #[test] fn bindgen_test_layout_rte_ring() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -109,6 +111,26 @@ fn bindgen_test_layout_rte_ring() { 8usize, concat!("Alignment of ", stringify!(rte_ring)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(memzone)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(prod)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize }, + 12usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(cons)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(ring)), + ); } impl Default for rte_ring { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs rename to bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index 81fc8359d9..be77dc75d4 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -129,6 +129,8 @@ pub struct rte_kni_fifo { } #[test] fn bindgen_test_layout_rte_kni_fifo() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -139,6 +141,36 @@ fn bindgen_test_layout_rte_kni_fifo() { 8usize, concat!("Alignment of ", stringify!(rte_kni_fifo)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(write)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(read)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(len)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(elem_size), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(buffer)), + ); } impl Default for rte_kni_fifo { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/inline_namespace_nested.rs b/bindgen-tests/tests/expectations/tests/libclang-5/inline_namespace_nested.rs deleted file mode 100644 index 996b877e50..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-5/inline_namespace_nested.rs +++ /dev/null @@ -1 +0,0 @@ -/* error generating bindings */ diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs b/bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs deleted file mode 100644 index 996b877e50..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs +++ /dev/null @@ -1 +0,0 @@ -/* error generating bindings */ diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs b/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs deleted file mode 100644 index 7ab3ac45ba..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#![cfg(target_os = "macos")] -use objc::{self, msg_send, sel, sel_impl, class}; -#[allow(non_camel_case_types)] -pub type id = *mut objc::runtime::Object; -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct Foo(pub id); -impl std::ops::Deref for Foo { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Foo {} -impl Foo { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(Foo), alloc) }) - } -} -impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref { - unsafe fn get(&self) -> *mut ObjectType - where - ::Target: objc::Message + Sized, - { - msg_send!(* self, get) - } -} -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct FooMultiGeneric(pub id); -impl std::ops::Deref for FooMultiGeneric { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for FooMultiGeneric {} -impl FooMultiGeneric { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) }) - } -} -impl IFooMultiGeneric -for FooMultiGeneric {} -pub trait IFooMultiGeneric< - KeyType: 'static, - ObjectType: 'static, ->: Sized + std::ops::Deref { - unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType - where - ::Target: objc::Message + Sized, - { - msg_send!(* self, objectForKey : key) - } -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/ptr32-has-different-size.rs b/bindgen-tests/tests/expectations/tests/libclang-5/ptr32-has-different-size.rs deleted file mode 100644 index 0d677052ea..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-5/ptr32-has-different-size.rs +++ /dev/null @@ -1,41 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct TEST_STRUCT { - pub ptr_32bit: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout_TEST_STRUCT() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TEST_STRUCT)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TEST_STRUCT)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr_32bit) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TEST_STRUCT), - "::", - stringify!(ptr_32bit), - ), - ); -} -impl Default for TEST_STRUCT { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -pub type TEST = TEST_STRUCT; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs b/bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs deleted file mode 100644 index 3cb7248c93..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { - #[link_name = "\u{1}_Z1bcz"] - pub fn b(arg1: ::std::os::raw::c_char, ...) -> ::std::os::raw::c_char; -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs b/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs deleted file mode 100644 index 340bc670dc..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Foo { - pub _address: u8, -} -pub const Foo_kFoo: bool = true; -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Bar { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_Z5Test2v"] - pub fn Test2() -> ::std::os::raw::c_uint; -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs deleted file mode 100644 index e3179543fc..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#![cfg(not(test))] -#[repr(C)] -#[derive(Default, Copy, Clone)] -pub struct JNINativeInterface_ { - pub GetVersion: ::std::option::Option< - unsafe extern "stdcall" fn( - env: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, - >, - pub __hack: ::std::os::raw::c_ulonglong, -} -#[test] -fn bindgen_test_layout_JNINativeInterface_() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(JNINativeInterface_)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(JNINativeInterface_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(GetVersion), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(__hack), - ), - ); -} -extern "stdcall" { - pub fn bar(); -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs deleted file mode 100644 index 19668a73dd..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs +++ /dev/null @@ -1,617 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -#[derive(Copy, Clone)] -pub struct C { - pub a: ::std::os::raw::c_int, - pub big_array: [::std::os::raw::c_char; 33usize], -} -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 40usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)), - ); -} -impl Default for C { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -pub struct C_with_zero_length_array { - pub a: ::std::os::raw::c_int, - pub big_array: [::std::os::raw::c_char; 33usize], - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_C_with_zero_length_array() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array), - ), - ); -} -impl Default for C_with_zero_length_array { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_zero_length_array_2 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_C_with_zero_length_array_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array), - ), - ); -} -#[repr(C)] -pub struct C_with_incomplete_array { - pub a: ::std::os::raw::c_int, - pub big_array: [::std::os::raw::c_char; 33usize], - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_C_with_incomplete_array() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C_with_incomplete_array)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(big_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(incomplete_array), - ), - ); -} -impl Default for C_with_incomplete_array { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_incomplete_array_2 { - pub a: ::std::os::raw::c_int, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_C_with_incomplete_array_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(C_with_incomplete_array_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(incomplete_array), - ), - ); -} -#[repr(C)] -pub struct C_with_zero_length_array_and_incomplete_array { - pub a: ::std::os::raw::c_int, - pub big_array: [::std::os::raw::c_char; 33usize], - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { - const UNINIT: ::std::mem::MaybeUninit< - C_with_zero_length_array_and_incomplete_array, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(big_array), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(zero_length_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(incomplete_array), - ), - ); -} -impl Default for C_with_zero_length_array_and_incomplete_array { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_zero_length_array_and_incomplete_array_2 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { - const UNINIT: ::std::mem::MaybeUninit< - C_with_zero_length_array_and_incomplete_array_2, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(zero_length_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(incomplete_array), - ), - ); -} -#[repr(C)] -#[derive(Debug, Default, Hash, PartialOrd, Ord, PartialEq, Eq)] -pub struct WithDtor { - pub b: ::std::os::raw::c_int, -} -#[test] -fn bindgen_test_layout_WithDtor() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithDtor)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDtor)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)), - ); -} -#[repr(C)] -pub struct IncompleteArrayNonCopiable { - pub whatever: *mut ::std::os::raw::c_void, - pub incomplete_array: __IncompleteArrayField, -} -#[test] -fn bindgen_test_layout_IncompleteArrayNonCopiable() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(whatever), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(incomplete_array), - ), - ); -} -impl Default for IncompleteArrayNonCopiable { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union Union { - pub d: f32, - pub i: ::std::os::raw::c_int, -} -#[test] -fn bindgen_test_layout_Union() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Union)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Union)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)), - ); -} -impl Default for Union { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Copy, Clone)] -pub struct WithUnion { - pub data: Union, -} -#[test] -fn bindgen_test_layout_WithUnion() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithUnion)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithUnion)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)), - ); -} -impl Default for WithUnion { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] -pub struct RealAbstractionWithTonsOfMethods { - pub _address: u8, -} -#[test] -fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)), - ); -} -extern "C" { - #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"] - pub fn RealAbstractionWithTonsOfMethods_bar( - this: *const RealAbstractionWithTonsOfMethods, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"] - pub fn RealAbstractionWithTonsOfMethods_bar1( - this: *mut RealAbstractionWithTonsOfMethods, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"] - pub fn RealAbstractionWithTonsOfMethods_bar2( - this: *mut RealAbstractionWithTonsOfMethods, - foo: ::std::os::raw::c_int, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3staEv"] - pub fn RealAbstractionWithTonsOfMethods_sta(); -} -impl RealAbstractionWithTonsOfMethods { - #[inline] - pub unsafe fn bar(&self) { - RealAbstractionWithTonsOfMethods_bar(self) - } - #[inline] - pub unsafe fn bar1(&mut self) { - RealAbstractionWithTonsOfMethods_bar1(self) - } - #[inline] - pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - RealAbstractionWithTonsOfMethods_bar2(self, foo) - } - #[inline] - pub unsafe fn sta() { - RealAbstractionWithTonsOfMethods_sta() - } -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs deleted file mode 100644 index b6544212cf..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs +++ /dev/null @@ -1,668 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Copy)] -pub struct C { - pub a: ::std::os::raw::c_int, - pub big_array: [::std::os::raw::c_char; 33usize], -} -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 40usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)), - ); -} -impl Clone for C { - fn clone(&self) -> Self { - *self - } -} -impl Default for C { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -impl ::std::cmp::PartialEq for C { - fn eq(&self, other: &C) -> bool { - self.a == other.a && &self.big_array[..] == &other.big_array[..] - } -} -#[repr(C)] -pub struct C_with_zero_length_array { - pub a: ::std::os::raw::c_int, - pub big_array: [::std::os::raw::c_char; 33usize], - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_C_with_zero_length_array() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array), - ), - ); -} -impl Default for C_with_zero_length_array { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_zero_length_array_2 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_C_with_zero_length_array_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array), - ), - ); -} -#[repr(C)] -pub struct C_with_incomplete_array { - pub a: ::std::os::raw::c_int, - pub big_array: [::std::os::raw::c_char; 33usize], - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_C_with_incomplete_array() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C_with_incomplete_array)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(big_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(incomplete_array), - ), - ); -} -impl Default for C_with_incomplete_array { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_incomplete_array_2 { - pub a: ::std::os::raw::c_int, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_C_with_incomplete_array_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(C_with_incomplete_array_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(incomplete_array), - ), - ); -} -#[repr(C)] -pub struct C_with_zero_length_array_and_incomplete_array { - pub a: ::std::os::raw::c_int, - pub big_array: [::std::os::raw::c_char; 33usize], - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { - const UNINIT: ::std::mem::MaybeUninit< - C_with_zero_length_array_and_incomplete_array, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(big_array), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(zero_length_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(incomplete_array), - ), - ); -} -impl Default for C_with_zero_length_array_and_incomplete_array { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_zero_length_array_and_incomplete_array_2 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { - const UNINIT: ::std::mem::MaybeUninit< - C_with_zero_length_array_and_incomplete_array_2, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(zero_length_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(incomplete_array), - ), - ); -} -#[repr(C)] -#[derive(Debug, Default, Hash, PartialEq, Eq)] -pub struct WithDtor { - pub b: ::std::os::raw::c_int, -} -#[test] -fn bindgen_test_layout_WithDtor() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithDtor)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDtor)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)), - ); -} -#[repr(C)] -pub struct IncompleteArrayNonCopiable { - pub whatever: *mut ::std::os::raw::c_void, - pub incomplete_array: __IncompleteArrayField, -} -#[test] -fn bindgen_test_layout_IncompleteArrayNonCopiable() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(whatever), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(incomplete_array), - ), - ); -} -impl Default for IncompleteArrayNonCopiable { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] -pub struct Union { - pub d: __BindgenUnionField, - pub i: __BindgenUnionField<::std::os::raw::c_int>, - pub bindgen_union_field: u32, -} -#[test] -fn bindgen_test_layout_Union() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Union)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Union)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)), - ); -} -impl Clone for Union { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] -pub struct WithUnion { - pub data: Union, -} -#[test] -fn bindgen_test_layout_WithUnion() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithUnion)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithUnion)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)), - ); -} -impl Clone for WithUnion { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct RealAbstractionWithTonsOfMethods { - pub _address: u8, -} -#[test] -fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)), - ); -} -extern "C" { - #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"] - pub fn RealAbstractionWithTonsOfMethods_bar( - this: *const RealAbstractionWithTonsOfMethods, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"] - pub fn RealAbstractionWithTonsOfMethods_bar1( - this: *mut RealAbstractionWithTonsOfMethods, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"] - pub fn RealAbstractionWithTonsOfMethods_bar2( - this: *mut RealAbstractionWithTonsOfMethods, - foo: ::std::os::raw::c_int, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3staEv"] - pub fn RealAbstractionWithTonsOfMethods_sta(); -} -impl Clone for RealAbstractionWithTonsOfMethods { - fn clone(&self) -> Self { - *self - } -} -impl RealAbstractionWithTonsOfMethods { - #[inline] - pub unsafe fn bar(&self) { - RealAbstractionWithTonsOfMethods_bar(self) - } - #[inline] - pub unsafe fn bar1(&mut self) { - RealAbstractionWithTonsOfMethods_bar1(self) - } - #[inline] - pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - RealAbstractionWithTonsOfMethods_bar2(self, foo) - } - #[inline] - pub unsafe fn sta() { - RealAbstractionWithTonsOfMethods_sta() - } -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs b/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs deleted file mode 100644 index 97cb7ec691..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -pub const k: bool = true; -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct A { - pub _address: u8, -} -pub const A_k: bool = false; -#[test] -fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)), - ); -} -pub type foo = bool; -pub const k2: foo = true; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs b/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs deleted file mode 100644 index bbcf6d5450..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; -pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; -#[repr(u32)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum _bindgen_ty_1 { - foo = 4, - bar = 8, -} -pub type EasyToOverflow = ::std::os::raw::c_ulonglong; -pub const k: EasyToOverflow = 2147483648; -pub const k_expr: EasyToOverflow = 1152921504606846976; -pub const wow: EasyToOverflow = 2147483648; -pub const BAZ: ::std::os::raw::c_longlong = 24; -pub const fuzz: f64 = 51.0; -pub const BAZZ: ::std::os::raw::c_char = 53; -pub const WAT: ::std::os::raw::c_char = 0; -pub const bytestring: &[u8; 4] = b"Foo\0"; -pub const NOT_UTF8: &[u8; 5] = b"\xF0(\x8C(\0"; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs new file mode 100644 index 0000000000..49498deaa5 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs @@ -0,0 +1,46 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct B { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct C { + pub _address: u8, +} +pub type C_U = B; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct A { + pub u: u8, +} +#[test] +fn bindgen_test_layout_A() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(A))); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(u)), + ); +} +#[test] +fn __bindgen_test_layout_C_open0_A_close0_instantiation() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(C)), + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(C)), + ); +} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs deleted file mode 100644 index d1b4c9004a..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ /dev/null @@ -1,154 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct test { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_test() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(test), "::", stringify!(a)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test), - "::", - stringify!(zero_length_array), - ), - ); -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct test2 { - pub a: ::std::os::raw::c_int, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_test2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test2), - "::", - stringify!(incomplete_array), - ), - ); -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct test3 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_test3() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test3)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test3)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(zero_length_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(incomplete_array), - ), - ); -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs b/bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs deleted file mode 100644 index 79004238fc..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ /dev/null @@ -1,3 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#![allow(overflowing_literals)] -pub const a: u32 = 4294967291; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs deleted file mode 100644 index c8038e1f40..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ /dev/null @@ -1,180 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { - storage: Storage, -} -impl __BindgenBitfieldUnit { - #[inline] - pub const fn new(storage: Storage) -> Self { - Self { storage } - } -} -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ - #[inline] - pub fn get_bit(&self, index: usize) -> bool { - debug_assert!(index / 8 < self.storage.as_ref().len()); - let byte_index = index / 8; - let byte = self.storage.as_ref()[byte_index]; - let bit_index = if cfg!(target_endian = "big") { - 7 - (index % 8) - } else { - index % 8 - }; - let mask = 1 << bit_index; - byte & mask == mask - } - #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { - debug_assert!(index / 8 < self.storage.as_ref().len()); - let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; - let bit_index = if cfg!(target_endian = "big") { - 7 - (index % 8) - } else { - index % 8 - }; - let mask = 1 << bit_index; - if val { - *byte |= mask; - } else { - *byte &= !mask; - } - } - #[inline] - pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), - ); - let mut val = 0; - for i in 0..(bit_width as usize) { - if self.get_bit(i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] - pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), - ); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - self.set_bit(index + bit_offset, val_bit_is_set); - } - } -} -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -#[derive(Debug)] -pub struct foo { - pub _bitfield_align_1: [u8; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, - pub b: __IncompleteArrayField<*mut ::std::os::raw::c_void>, -} -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), - ); -} -impl Default for foo { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -impl foo { - #[inline] - pub fn a(&self) -> ::std::os::raw::c_char { - unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } - } - #[inline] - pub fn set_a(&mut self, val: ::std::os::raw::c_char) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - self._bitfield_1.set(0usize, 1u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - a: ::std::os::raw::c_char, - ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); - __bindgen_bitfield_unit - .set( - 0usize, - 1u8, - { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }, - ); - __bindgen_bitfield_unit - } -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs new file mode 100644 index 0000000000..5c5ad156e3 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs @@ -0,0 +1,17 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Foo { + pub member: *mut [u8; 0usize], +} +pub type Foo_FirstAlias = [u8; 0usize]; +pub type Foo_SecondAlias = [u8; 0usize]; +impl Default for Foo { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs deleted file mode 100644 index 520b3b0ecd..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ /dev/null @@ -1,148 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -#[derive(Debug)] -pub struct rte_ring { - pub memzone: *mut rte_memzone, - pub prod: rte_ring_prod, - pub cons: rte_ring_cons, - pub ring: __IncompleteArrayField<*mut ::std::os::raw::c_void>, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct rte_ring_prod { - pub watermark: ::std::os::raw::c_uint, -} -#[test] -fn bindgen_test_layout_rte_ring_prod() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ring_prod)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ring_prod)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_prod), - "::", - stringify!(watermark), - ), - ); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct rte_ring_cons { - pub sc_dequeue: ::std::os::raw::c_uint, -} -#[test] -fn bindgen_test_layout_rte_ring_cons() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ring_cons)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ring_cons)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_cons), - "::", - stringify!(sc_dequeue), - ), - ); -} -#[test] -fn bindgen_test_layout_rte_ring() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(rte_ring)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_ring)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(memzone)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(prod)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize }, - 12usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(cons)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(ring)), - ); -} -impl Default for rte_ring { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct rte_memzone { - pub _address: u8, -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs deleted file mode 100644 index ef830ca69e..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs +++ /dev/null @@ -1,60 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] -pub mod root { - #[allow(unused_imports)] - use self::super::root; - #[repr(C)] - #[derive(Debug, Copy, Clone)] - pub struct Rooted { - pub member: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, - } - impl Default for Rooted { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } - } - pub type AutoValueVector_Alias = ::std::os::raw::c_int; - #[test] - fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted < ::std::os::raw::c_int >), - ), - ); - } - #[test] - fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted < root::AutoValueVector_Alias >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted < root::AutoValueVector_Alias >), - ), - ); - } -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs deleted file mode 100644 index be77dc75d4..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs +++ /dev/null @@ -1,291 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { - storage: Storage, -} -impl __BindgenBitfieldUnit { - #[inline] - pub const fn new(storage: Storage) -> Self { - Self { storage } - } -} -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ - #[inline] - pub fn get_bit(&self, index: usize) -> bool { - debug_assert!(index / 8 < self.storage.as_ref().len()); - let byte_index = index / 8; - let byte = self.storage.as_ref()[byte_index]; - let bit_index = if cfg!(target_endian = "big") { - 7 - (index % 8) - } else { - index % 8 - }; - let mask = 1 << bit_index; - byte & mask == mask - } - #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { - debug_assert!(index / 8 < self.storage.as_ref().len()); - let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; - let bit_index = if cfg!(target_endian = "big") { - 7 - (index % 8) - } else { - index % 8 - }; - let mask = 1 << bit_index; - if val { - *byte |= mask; - } else { - *byte &= !mask; - } - } - #[inline] - pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), - ); - let mut val = 0; - for i in 0..(bit_width as usize) { - if self.get_bit(i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] - pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), - ); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - self.set_bit(index + bit_offset, val_bit_is_set); - } - } -} -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -#[derive(Debug)] -pub struct rte_kni_fifo { - ///< Next position to be written - pub write: ::std::os::raw::c_uint, - ///< Next position to be read - pub read: ::std::os::raw::c_uint, - ///< Circular buffer length - pub len: ::std::os::raw::c_uint, - ///< Pointer size - for 32/64 bit OS - pub elem_size: ::std::os::raw::c_uint, - ///< The buffer contains mbuf pointers - pub buffer: __IncompleteArrayField<*mut ::std::os::raw::c_void>, -} -#[test] -fn bindgen_test_layout_rte_kni_fifo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(rte_kni_fifo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_kni_fifo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(write)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(read)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(len)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(elem_size), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(buffer)), - ); -} -impl Default for rte_kni_fifo { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[repr(align(8))] -#[derive(Debug, Default, Copy, Clone)] -pub struct rte_eth_link { - ///< ETH_SPEED_NUM_ - pub link_speed: u32, - pub _bitfield_align_1: [u8; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, - pub __bindgen_padding_0: [u8; 3usize], -} -#[test] -fn bindgen_test_layout_rte_eth_link() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_eth_link)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_eth_link)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_link), - "::", - stringify!(link_speed), - ), - ); -} -impl rte_eth_link { - #[inline] - pub fn link_duplex(&self) -> u16 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } - } - #[inline] - pub fn set_link_duplex(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(0usize, 1u8, val as u64) - } - } - #[inline] - pub fn link_autoneg(&self) -> u16 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } - } - #[inline] - pub fn set_link_autoneg(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(1usize, 1u8, val as u64) - } - } - #[inline] - pub fn link_status(&self) -> u16 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } - } - #[inline] - pub fn set_link_status(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(2usize, 1u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - link_duplex: u16, - link_autoneg: u16, - link_status: u16, - ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); - __bindgen_bitfield_unit - .set( - 0usize, - 1u8, - { - let link_duplex: u16 = unsafe { ::std::mem::transmute(link_duplex) }; - link_duplex as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 1usize, - 1u8, - { - let link_autoneg: u16 = unsafe { - ::std::mem::transmute(link_autoneg) - }; - link_autoneg as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 2usize, - 1u8, - { - let link_status: u16 = unsafe { ::std::mem::transmute(link_status) }; - link_status as u64 - }, - ); - __bindgen_bitfield_unit - } -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs deleted file mode 100644 index 34efb92461..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs +++ /dev/null @@ -1,46 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { - pub fn foo(); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Foo { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}?sBar@Foo@@2_NA"] - pub static mut Foo_sBar: bool; -} -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} -extern "fastcall" { - pub fn fast_call_func_no_args() -> ::std::os::raw::c_int; -} -extern "fastcall" { - pub fn fast_call_func_many_args( - arg1: ::std::os::raw::c_int, - arg2: ::std::os::raw::c_int, - arg3: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "stdcall" { - pub fn std_call_func_no_args() -> ::std::os::raw::c_int; -} -extern "stdcall" { - pub fn std_call_func_many_args( - arg1: ::std::os::raw::c_int, - arg2: ::std::os::raw::c_int, - arg3: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs deleted file mode 100644 index 6fb4e6b857..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs +++ /dev/null @@ -1,107 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#![cfg(target_os = "macos")] -use objc::{self, msg_send, sel, sel_impl, class}; -#[allow(non_camel_case_types)] -pub type id = *mut objc::runtime::Object; -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct Foo(pub id); -impl std::ops::Deref for Foo { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Foo {} -impl Foo { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(Foo), alloc) }) - } -} -impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref {} -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct Bar(pub id); -impl std::ops::Deref for Bar { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Bar {} -impl Bar { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(Bar), alloc) }) - } -} -impl IFoo for Bar {} -impl From for Foo { - fn from(child: Bar) -> Foo { - Foo(child.0) - } -} -impl std::convert::TryFrom for Bar { - type Error = &'static str; - fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Bar)) }; - if is_kind_of { - Ok(Bar(parent.0)) - } else { - Err("This Foo cannot be downcasted to Bar") - } - } -} -impl IBar for Bar {} -pub trait IBar: Sized + std::ops::Deref {} -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct Baz(pub id); -impl std::ops::Deref for Baz { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Baz {} -impl Baz { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(Baz), alloc) }) - } -} -impl IBar for Baz {} -impl From for Bar { - fn from(child: Baz) -> Bar { - Bar(child.0) - } -} -impl std::convert::TryFrom for Baz { - type Error = &'static str; - fn try_from(parent: Bar) -> Result { - let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Baz)) }; - if is_kind_of { - Ok(Baz(parent.0)) - } else { - Err("This Bar cannot be downcasted to Baz") - } - } -} -impl IFoo for Baz {} -impl From for Foo { - fn from(child: Baz) -> Foo { - Foo(child.0) - } -} -impl std::convert::TryFrom for Baz { - type Error = &'static str; - fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Baz)) }; - if is_kind_of { - Ok(Baz(parent.0)) - } else { - Err("This Foo cannot be downcasted to Baz") - } - } -} -impl IBaz for Baz {} -pub trait IBaz: Sized + std::ops::Deref {} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs deleted file mode 100644 index 3ba3a82aa3..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs +++ /dev/null @@ -1,33 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Base { - pub _address: u8, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Derived { - pub b: bool, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Usage { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_ZN5Usage13static_memberE"] - pub static mut Usage_static_member: [u32; 2usize]; -} -#[test] -fn bindgen_test_layout_Usage() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Usage)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Usage)), - ); -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs new file mode 100644 index 0000000000..44afa4822a --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs @@ -0,0 +1,87 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub mod root { + #[allow(unused_imports)] + use self::super::root; + pub mod whatever { + #[allow(unused_imports)] + use self::super::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] + pub struct typedef_struct { + pub foo: ::std::os::raw::c_int, + } + #[test] + fn bindgen_test_layout_typedef_struct() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(typedef_struct)), + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(typedef_struct)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(typedef_struct), + "::", + stringify!(foo), + ), + ); + } + #[repr(u32)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] + pub enum typedef_enum { + BAR = 1, + } + } + pub mod _bindgen_mod_id_12 { + #[allow(unused_imports)] + use self::super::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] + pub struct _bindgen_ty_1 { + pub foo: ::std::os::raw::c_int, + } + #[test] + fn bindgen_test_layout__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<_bindgen_ty_1>(), + 4usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)), + ); + assert_eq!( + ::std::mem::align_of::<_bindgen_ty_1>(), + 4usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(foo), + ), + ); + } + pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; + pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; + #[repr(u32)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] + pub enum _bindgen_ty_2 { + BAR = 1, + } + pub use self::super::super::root::_bindgen_mod_id_12::_bindgen_ty_2 as typedef_enum; + } +} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs deleted file mode 100644 index d585a857d9..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Rooted { - pub ptr: MaybeWrapped<::std::os::raw::c_int>, -} -#[test] -fn bindgen_test_layout_Rooted() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Rooted)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Rooted)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Rooted), "::", stringify!(ptr)), - ); -} -impl Default for Rooted { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -///
-pub type MaybeWrapped
= a; -#[test] -fn __bindgen_test_layout_MaybeWrapped_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(MaybeWrapped < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(MaybeWrapped < ::std::os::raw::c_int >), - ), - ); -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs deleted file mode 100644 index bc4b660029..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ /dev/null @@ -1,170 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -/// Bizarrely enough, this should *not* get an `_address` field. -#[repr(C)] -#[derive(Debug, Default)] -pub struct ZeroSizedArray { - pub arr: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_ZeroSizedArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ZeroSizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ZeroSizedArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ZeroSizedArray), "::", stringify!(arr)), - ); -} -/// And nor should this get an `_address` field. -#[repr(C)] -#[derive(Debug, Default)] -pub struct ContainsZeroSizedArray { - pub zsa: ZeroSizedArray, -} -#[test] -fn bindgen_test_layout_ContainsZeroSizedArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ContainsZeroSizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ContainsZeroSizedArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsZeroSizedArray), - "::", - stringify!(zsa), - ), - ); -} -/** Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted - either.*/ -#[repr(C)] -#[derive(Debug, Default)] -pub struct InheritsZeroSizedArray { - pub _base: ZeroSizedArray, -} -#[test] -fn bindgen_test_layout_InheritsZeroSizedArray() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(InheritsZeroSizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(InheritsZeroSizedArray)), - ); -} -/// And this should not get an `_address` field either. -#[repr(C)] -#[derive(Debug, Default)] -pub struct DynamicallySizedArray { - pub arr: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_DynamicallySizedArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(DynamicallySizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(DynamicallySizedArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(DynamicallySizedArray), - "::", - stringify!(arr), - ), - ); -} -/// No `_address` field here either. -#[repr(C)] -#[derive(Debug, Default)] -pub struct ContainsDynamicallySizedArray { - pub dsa: DynamicallySizedArray, -} -#[test] -fn bindgen_test_layout_ContainsDynamicallySizedArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ContainsDynamicallySizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsDynamicallySizedArray), - "::", - stringify!(dsa), - ), - ); -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/mangling-win32.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs rename to bindgen-tests/tests/expectations/tests/mangling-win32.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/objc_inheritance.rs b/bindgen-tests/tests/expectations/tests/objc_inheritance.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/objc_inheritance.rs rename to bindgen-tests/tests/expectations/tests/objc_inheritance.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs b/bindgen-tests/tests/expectations/tests/objc_template.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs rename to bindgen-tests/tests/expectations/tests/objc_template.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs rename to bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs index 44afa4822a..aabe23b18e 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs @@ -47,41 +47,38 @@ pub mod root { use self::super::super::root; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] - pub struct _bindgen_ty_1 { + pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } #[test] - fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); + fn bindgen_test_layout_typedef_struct() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), + ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)), + concat!("Size of: ", stringify!(typedef_struct)), ); assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), + ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)), + concat!("Alignment of ", stringify!(typedef_struct)), ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(_bindgen_ty_1), + stringify!(typedef_struct), "::", stringify!(foo), ), ); } - pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; - pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] - pub enum _bindgen_ty_2 { + pub enum typedef_enum { BAR = 1, } - pub use self::super::super::root::_bindgen_mod_id_12::_bindgen_ty_2 as typedef_enum; } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs rename to bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs diff --git a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs index b0a1d3e538..bc4b660029 100644 --- a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs @@ -114,6 +114,8 @@ pub struct DynamicallySizedArray { } #[test] fn bindgen_test_layout_DynamicallySizedArray() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -124,6 +126,16 @@ fn bindgen_test_layout_DynamicallySizedArray() { 1usize, concat!("Alignment of ", stringify!(DynamicallySizedArray)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(DynamicallySizedArray), + "::", + stringify!(arr), + ), + ); } /// No `_address` field here either. #[repr(C)] @@ -133,6 +145,8 @@ pub struct ContainsDynamicallySizedArray { } #[test] fn bindgen_test_layout_ContainsDynamicallySizedArray() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -143,4 +157,14 @@ fn bindgen_test_layout_ContainsDynamicallySizedArray() { 1usize, concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsDynamicallySizedArray), + "::", + stringify!(dsa), + ), + ); } diff --git a/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp b/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp index f3467f4528..b41b422d1e 100644 --- a/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp +++ b/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp @@ -4,5 +4,12 @@ template struct Foo { template using FirstAlias = typename T::Associated; template using SecondAlias = Foo>; + +#if 0 + // FIXME: This regressed sometime between libclang 9 and 16, though it + // never quite worked properly so... SecondAlias member; +#else + SecondAlias* member; +#endif }; diff --git a/bindgen-tests/tests/stylo_sanity.rs b/bindgen-tests/tests/stylo_sanity.rs index e1ad86b04d..e9ec69bcb8 100755 --- a/bindgen-tests/tests/stylo_sanity.rs +++ b/bindgen-tests/tests/stylo_sanity.rs @@ -19,8 +19,8 @@ extern crate bindgen; feature = "__testing_only_extra_assertions", )))] #[cfg(any( - feature = "__testing_only_libclang_5", - feature = "__testing_only_libclang_9" + feature = "__testing_only_libclang_9", + feature = "__testing_only_libclang_16" ))] fn sanity_check_can_generate_stylo_bindings() { use std::time::Instant; diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 1913b874f0..bcc02b8dfe 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -148,21 +148,19 @@ fn compare_generated_header( { let mut expectation = expectation.clone(); - if cfg!(feature = "__testing_only_libclang_9") { + if cfg!(feature = "__testing_only_libclang_16") { + expectation.push("libclang-16"); + } else if cfg!(feature = "__testing_only_libclang_9") { expectation.push("libclang-9"); - } else if cfg!(feature = "__testing_only_libclang_5") { - expectation.push("libclang-5"); } else { match clang_version().parsed { - None => expectation.push("libclang-9"), + None => expectation.push("libclang-16"), Some(version) => { let (maj, min) = version; - let version_str = if maj >= 9 { + let version_str = if maj >= 16 { + "16".to_owned() + } else if maj >= 9 { "9".to_owned() - } else if maj >= 5 { - "5".to_owned() - } else if maj >= 4 { - "4".to_owned() } else { format!("{}.{}", maj, min) }; diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 7dd4d01d29..733679a603 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -58,7 +58,7 @@ __cli = [] # Features used for CI testing __testing_only_extra_assertions = [] __testing_only_libclang_9 = [] -__testing_only_libclang_5 = [] +__testing_only_libclang_16 = [] [package.metadata.docs.rs] features = ["experimental"] diff --git a/ci/test.sh b/ci/test.sh index c0c8bec59b..11e091f49f 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -9,20 +9,22 @@ set -x set -o pipefail function llvm_linux_target_triple() { - echo "x86_64-linux-gnu-ubuntu-16.04" + case "$1" in + 9.0.1) echo "x86_64-linux-gnu-ubuntu-16.04" ;; + *) echo "x86_64-linux-gnu-ubuntu-18.04" ;; + esac } function llvm_macos_target_triple() { case "$1" in - [0-8].* | 9.0.0) echo "x86_64-darwin-apple" ;; - # Starting with 9.0.1, triple swapped ordering - *) echo "x86_64-apple-darwin" ;; + 9.0.1) echo "x86_64-apple-darwin" ;; + *) echo "arm64-apple-darwin22.0" ;; esac } function llvm_version_triple() { case "$1" in - 5.0) echo "5.0.1" ;; + 9.0) echo "9.0.1" ;; # By default, take the .0 patch release *) echo "$1.0" ;; esac @@ -30,16 +32,7 @@ function llvm_version_triple() { function llvm_base_url() { local llvm_version_triple=$1 - - case "$llvm_version_triple" in - [0-8].* | 9.0.0) - echo "http://releases.llvm.org/$llvm_version_triple" - ;; - # Starting with 9.0.1, releases are hosted on github - *) - echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple" - ;; - esac + echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple" } function llvm_download() {