summaryrefslogtreecommitdiff
path: root/src/ir/comp.rs
AgeCommit message (Collapse)Author
2022-10-04split the repo into a workspaceChristian Poveda
remove `clap` dependency :tada: update the book installation instructions
2022-09-22codegen: Implement manuallydrop fields better.Emilio Cobos Álvarez
This doesn't change behavior but makes the code make more sense.
2022-09-01address clippy lintsChristian Poveda
2022-08-25Generate opaque type for template param dependent bit field widthCollin Baker
libclang's API does not provide a straightforward way to check for this, and calling clang_getFieldDeclBitWidth is actively unsafe in this case. See https://github.com/llvm/llvm-project/issues/56644 We probably can't generate reasonable bindings for such a type, so make the binding opaque. Ideally libclang would report if the bit width could not be evaluated. Unfortunately making such a change would mean bumping the minimum libclang version from 6.0 to 15.0. Instead, add logic to traverse the AST subtree starting from the field's bit width specifier looking for template parameters. If we find one, we make the resulting type opaque.
2021-10-27Fix warningsMikuroXina
2021-07-31Don't assume that an inner class declaration always immediately yields aPatrick Walton
complete type. It might not if we had to avoid recursion when processing types. Detect that case and bail out. This bug was being masked by the fact that we didn't always find definitions for the recursion check and so it didn't trigger, but now that this check is more reliable we have to be careful in more places. The test case was reduced from the GCC STL allocator definition.
2021-06-21comp: Do a better effort of computing packedness before bitfield units.Emilio Cobos Álvarez
Fixes #2067
2021-05-18Identify forward declarations in params. (#2052)Adrian Taylor
2021-02-07codegen: Track union layout more accurately.Emilio Cobos Álvarez
Instead of always generating the _bindgen_union_align method (which shouldn't be needed at all for Rust structs, since the struct layout tracker already deals with adding repr(align) as necessary) make sure to visit all fields appropriately to generate the correct alignment.
2021-01-29Generate fields as non-pub if they would be access restricted in C++.Weston Carvalho
2020-12-20comp: Fix bitfields to allow underaligned fields after them to take padding ↵Emilio Cobos Álvarez
space. Fixes #1947. There are two separate issues here: First, the change in comp.rs ensures that we don't round up the amount of storage to the alignment of the bitfield. That generates the "expected" output in #1947 (`__BindgenBitfieldUnit<[u8; 3], u16>`). But that's still not enough to fix that test-case because __BindgenBitfieldUnit would be aligned and have padding, and Rust won't put the extra field in the padding. In order to ensure the bitfield starts at the right alignment, but that Rust can put stuff in the extra field, we need to make a breaking change and split the generated fields in two: One preceding that guarantees alignment, and the actual storage, bit-aligned. This keeps the existing behavior while fixing that test-case.
2020-12-15Remove unsued mutable field logic.Weston Carvalho
2020-11-28struct_layout: Fix field offset computation for packed(n) structs.Emilio Cobos Álvarez
This can cause unnecessary padding to be computed otherwise at the end of the struct. With repr(packed(n)), a field can have padding to adjacent fields as long as its alignment is less than n. So reuse the code we have to align to a field layout, aligning to the struct layout instead. Fixes #1934
2020-08-04Make anon-fields-prefix non-optionalDarren Kulp
2020-08-04Add --anon-fields-prefix optionVarphone Wong
Allow to use the given prefix for the anon fields instead of `__bindgen_anon_`.
2020-07-20Avoid needless `std::mem::replace`Darren Kulp
In Rust 1.45.0, `std::mem::replace` gained the `#[must_use]` attribute, causing a new diagnostic for some `bindgen` code : error: unused return value of `std::mem::replace` that must be used --> src/ir/comp.rs:751:17 | 751 | / mem::replace( 752 | | self, 753 | | CompFields::AfterComputingBitfieldUnits { 754 | | fields, 755 | | has_bitfield_units, 756 | | }, 757 | | ); | |__________________^ | = note: `-D unused-must-use` implied by `-D warnings` = note: if you don't need the old value, you can just assign the new value directly error: unused return value of `std::mem::replace` that must be used --> src/ir/comp.rs:760:17 | 760 | mem::replace(self, CompFields::ErrorComputingBitfieldUnits); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: if you don't need the old value, you can just assign the new value directly error: aborting due to 2 previous errors
2020-04-27Run `cargo fmt`Joshua Nelson
2020-04-27Run `cargo fix --edition`Joshua Nelson
2020-04-26Really minor cleanup.Emilio Cobos Álvarez
2020-03-10ir: Remove redundant parenthesis.Emilio Cobos Álvarez
2020-02-02ir: codegen: Handle too large bitfield units.Emilio Cobos Álvarez
By not generating various code for it. In the future, we could improve on this by splitting contiguous bitfield units, if needed, so that we can implement them without dealing with rust array derive limits. Fixes #1718
2020-01-29ir: Account for packedness when computing bitfield sizes.Emilio Cobos Álvarez
Fixes #1716
2019-09-17Rustfmt.Emilio Cobos Álvarez
2019-07-23Don't emit #[repr(align(0))] for empty unions (#1595)Patrick Marks
2019-07-15Fix layout computation for union forward declarations (#1593)Patrick Marks
2019-05-21Update LinksAlex Touchet
2019-04-26Remove redundant imports.Emilio Cobos Álvarez
2019-01-18Fix layout with packed class that only has a vtableTom Tromey
I noticed that a `#pragma packed` class that has only a vtable but no data members is not marked repr(packed). The bug is that is_packed examines data members but not the vtable when applying its heuristic.
2019-01-08Support #[repr(packed(N))] on Rust 1.33+Christian Legnitto
Fixes https://github.com/rust-lang/rust-bindgen/issues/537.
2018-12-23Switch to FxHash for hash maps and such.Emilio Cobos Álvarez
This isn't such a massive win as I'd have hoped, but it is consistently faster, so there's no reason not to. > ./bindgen-old tests/stylo.hpp --no-rustfmt-bindings > /dev/null 2>&1 6.17s user 0.84s system 98% cpu 7.079 total > ./target/release/bindgen tests/stylo.hpp --no-rustfmt-bindings > /dev/null 2> 5.92s user 0.87s system 98% cpu 6.866 total Which isn't _that_ much but it's quite a bit.
2018-06-13Fix typos.Bruce Mitchener
2018-04-08TemplateParameters.all_template_params doesn't return OptionTamir Duberstein
2018-04-08TemplateParameters.self_template_params doesn't return OptionTamir Duberstein
2018-03-31ir: Remove an assertion that happens to be invalid.Emilio Cobos Álvarez
You can define a struct declared in an outer scope inside another struct, and the compiler won't even complain... C, what a language. Fixes #1281
2018-03-13Add a kill-switch for untagged unions.Emilio Cobos Álvarez
Otherwise we can't use repr(align) on stylo.
2018-03-04Untry.Emilio Cobos Álvarez
Use the ? operator instead of try, and add some more uses of it on Option<> that were straight-forward.
2018-01-29codegen: Make forward declarations go through the more generic path.Emilio Cobos Álvarez
Instead of special-casing. This allows to use the normal flags to control what can be or not derived for them. Arguably deriving Copy / Clone is kind of busted for those, but changing this by default broke tests (RefPtr<ForwardDeclaredType> stopped working for example). So I think this is a good compromise. Fixes #1238
2017-12-29Don't generate symbols for pure virtual functions.Emilio Cobos Álvarez
Fixes #1197.
2017-11-03Make bitfield unit allocation fallibleNick Fitzgerald
Instead of panicking when we see a bitfield that does not have a layout, return an error up the stack. If we get an error when allocating bitfields into units, then make the whole struct opaque. Fixes #1140
2017-11-02Detect `#pragma pack(...)` and make `pack(n)` where `n > 1` opaqueNick Fitzgerald
This is a bandaid for #537. It does *not* fix the underlying issue, which requires `#[repr(packed = "N")]` support in Rust. However, it does make sure that we don't generate type definitions with the wrong layout, or fail our generated layout tests.
2017-10-31Unnamed bit-fields should not affect alignmentNick Fitzgerald
According to the x86[-64] ABI spec: "Unnamed bit-fields’ types do not affect the alignment of a structure or union". This makes sense: such bit-fields are only used for padding, and we can't perform an un-aligned read of something we can't read because we can't even name it. Fixes #1076
2017-10-31Remove unused assignmentNick Fitzgerald
2017-10-25Compute sizedness with a fixed-point analysisNick Fitzgerald
This fixes a couple bugs where we weren't properly adding an `_address` byte. It also helps pave the way for computing implicit fields (such as padding, `_address`, vtable pointers, etc) in its own pass, before codegen. Fixes #768
2017-10-24Auto merge of #1095 - emilio:nits, r=pepyakinbors-servo
ir: Cleanup a bunch of constructors Should be no change in behavior.
2017-10-24ir: Cleanup a bunch of constructorsEmilio Cobos Álvarez
To use the shorthand initialization syntax.
2017-10-23Remove `CompInfo::needs_explicit_vtable` and use `HasVtable::has_vtable_ptr` ↵Nick Fitzgerald
instead
2017-10-23Add `HasVtable::has_vtable_ptr` for querying if a type has its own vtable ↵Nick Fitzgerald
pointer
2017-10-12Rename `bitfield` to `bitfield_width`Nick Fitzgerald
Its more clear what the methods/fields are returning/storing when we add "width" to the name.
2017-10-09Fix bitfields in untagged Rust unionsSergey Pepyakin
2017-10-05Review fixesSergey Pepyakin