Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix template union forward declaration, close #1768 #2423

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Danielmelody
Copy link

No description provided.

@pvdrz pvdrz linked an issue Feb 23, 2023 that may be closed by this pull request
@Danielmelody Danielmelody force-pushed the main branch 2 times, most recently from 380937f to 0a09719 Compare February 23, 2023 16:32
@Danielmelody
Copy link
Author

Any review progress?

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one LGTM @emilio

@@ -1275,6 +1275,9 @@ impl CompInfo {
CXCursor_ParmDecl => true,
CXCursor_StructDecl | CXCursor_UnionDecl |
CXCursor_ClassDecl => !cur.is_definition(),
CXCursor_ClassTemplate => {
kind == CompKind::Union && !cur.is_definition()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not an issue for structs?

Copy link

@aleb aleb Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below is a sample union XXX item failing. The panic happens because no layout can be obtained from the item. This happens because layout: None and (in case of Unions) fields: []. In case of struct XXX, the codepath is different, the layout is simply not mandatory. See audocxx-bindgen/.../codegen/mod.rs:

impl CodeGenerator for CompInfo {

    fn codegen(...) {
        ...
        if is_opaque {
            ...
        } else if !is_union && !zero_sized {
            ... struct handled here, basically nothing is done without a `layout`
        } else if is_union && !forward_decl {
            // TODO(emilio): It'd be nice to unify this with the struct path
            // above somehow.
            let layout = layout.expect("Unable to get layout information?");
            ...
        }

        ...
    }
  cargo:warning=MESSAGE:<CompInfo as CodeGenerator>::codegen: item = Item { id: ItemId(23), local_id: OnceCell(<uninit>), next_child_local_id: Cell { value: 1 }, canonical_name: OnceCell(<uninit>), path_for_allowlisting: OnceCell(["root", "Sandwich"]), comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, disallow_debug: false, disallow_default: false, must_use_type: false, visibility_kind: None, accessor_kind: None, constify_enum_variant: false, derives: [] }, parent_id: ItemId(0), kind: Type(Type { name: Some("Sandwich"), layout: None, kind: Comp(CompInfo { kind: Union, visibility: Public, fields: After { fields: [], has_bitfield_units: false }, template_params: [TypeId(ItemId(24))], methods: [], constructors: [], destructor: None, base_members: [], inner_types: [], inner_vars: [], has_own_virtual_method: false, has_destructor: false, has_nonempty_base: false, has_non_type_template_params: false, has_unevaluable_bit_field_width: false, packed_attr: false, found_unknown_attr: false, is_forward_declaration: false }), is_const: false }), location: Some(include/aaa.hh:3:7) }
  cargo:warning=MESSAGE:Offset: _address: 0 -> 1
  thread 'main' panicked at /home/minion/.cargo/registry/src/index.crates.io-6f17d22bba15001f/autocxx-bindgen-0.69.5/codegen/mod.rs:2291:33:
  Unable to get layout information?

(obtained from https://github.com/aleb/autocxx-test/tree/v1 with RUST_LOG=debug RUST_BACKTRACE=full cargo build -r with this include.h)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic with 'Unable to get layout information?'
5 participants