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

Support Zero Sized Unions #415

Closed
XAMPPRocky opened this issue Feb 11, 2021 · 1 comment · Fixed by #780
Closed

Support Zero Sized Unions #415

XAMPPRocky opened this issue Feb 11, 2021 · 1 comment · Fixed by #780
Labels
a: rust-lang Issues specific to rust-lang/rust. t: enhancement A new feature or improvement to an existing one.

Comments

@XAMPPRocky
Copy link
Member

XAMPPRocky commented Feb 11, 2021

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
@XAMPPRocky XAMPPRocky added t: enhancement A new feature or improvement to an existing one. a: rust-lang Issues specific to rust-lang/rust. labels Feb 11, 2021
@khyperia
Copy link
Contributor

Specifically, zero-sized unions panic. Positively sized unions seem to work fine, changing the shader playground link to this compiles without issue:

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

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

union Foo { a: u32 }

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: rust-lang Issues specific to rust-lang/rust. t: enhancement A new feature or improvement to an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants