Skip to content

Wrong layout for generic union when not used untagged unions. #1503

Open
@emilio

Description

@emilio

Input C/C++ Header

enum class StyleTimingKeyword : unsigned char {
  Foo,
  Bar,
};

enum class StyleStepPosition : unsigned char {
  Baz,
  Bar,
};

template<typename Integer, typename Number>
union StyleTimingFunction {
  enum class Tag : unsigned char {
    Keyword,
    CubicBezier,
    Steps
  };

  struct Keyword_Body {
    Tag tag;
    StyleTimingKeyword _0;
  };

  struct CubicBezier_Body {
    Tag tag;
    Number x1;
    Number y1;
    Number x2;
    Number y2;
  };

  struct Steps_Body {
    Tag tag;
    Integer _0;
    StyleStepPosition _1;
  };

  struct {
    Tag tag;
  };
  Keyword_Body keyword;
  CubicBezier_Body cubic_bezier;
  Steps_Body steps;
};

struct Foo {
  StyleTimingFunction<int, float> f;
};

Bindgen Invocation

$ ./target/debug/bindgen --rust-target 1.0 t.hpp -o out.rs
$ rustc --test out.rs
$ ./out

Actual Results

---- __bindgen_test_layout_StyleTimingFunction_open0_int_float_close0_instantiation stdout ----
thread '__bindgen_test_layout_StyleTimingFunction_open0_int_float_close0_instantiation' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `20`: Size of template specialization: StyleTimingFunction < :: std :: os :: raw :: c_int , f32 >', out.rs:131:5

The union has:

    pub bindgen_union_field: [u8; 0usize],

Because we cannot determine the struct layout at that point.

Expected Results

The test passes. We get this right with untagged unions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions