Skip to content

Support Zero Sized Unions #415

Closed
@XAMPPRocky

Description

@XAMPPRocky

Using unions currently causes panics, while mostly used for C FFI in Rust, there are couple of cases where they are used in Rust code, the main one being core::mem::MaybeUninit.

Example

Shader playground

#![no_std]
#![feature(register_attr)]
#![register_attr(spirv)]

use spirv_std::glam::{  Vec4 };
use spirv_std::storage_class::{ Output };

union Foo { a: () }

#[allow(unused_attributes)]
#[spirv(fragment)]
pub fn main_fs(mut _output: Output<Vec4>)
{
    let _a = Foo { a: () };
}

Error Message

thread 'rustc' panicked at 'assertion failed: `(left != right)`
  left: `0`,
 right: `0`: TyAndLayout {
    ty: Foo,
    layout: Layout {
        fields: Union(
            1,
        ),
        variants: Single {
            index: 0,
        },
        abi: Aggregate {
            sized: true,
        },
        largest_niche: None,
        align: AbiAndPrefAlign {
            abi: Align {
                pow2: 0,
            },
            pref: Align {
                pow2: 3,
            },
        },
        size: Size {
            raw: 0,
        },
    },
}', crates\rustc_codegen_spirv\src\abi.rs:638:13

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: rust-langIssues specific to rust-lang/rust.t: enhancementA new feature or improvement to an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions