Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1600,9 +1600,9 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
// Same note and TODO as exactudiv
simple_op! {
exactsdiv,
sint: s_div,
int: s_div,
fold_const {
sint(a, b) => a.checked_div(b)?;
int(a, b) => a.checked_div(b)?;
}
}
simple_op! {fdiv, float: f_div}
Expand Down Expand Up @@ -1648,9 +1648,9 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
}
simple_uni_op! {
neg,
sint: s_negate,
int: s_negate,
fold_const {
sint(a) => a.checked_neg()?;
int(a) => a.checked_neg()?;
}
}
simple_uni_op! {fneg, float: f_negate}
Expand Down
7 changes: 4 additions & 3 deletions crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,10 @@ impl<'tcx> CodegenCx<'tcx> {
SpirvType::Array { count, .. } => {
u64::try_from(self.builder.lookup_const_scalar(count).unwrap()).unwrap()
}
SpirvType::RuntimeArray { .. } => {
(alloc.inner().size() - offset).bytes() / stride.bytes()
}
SpirvType::RuntimeArray { .. } => (alloc.inner().size() - offset)
.bytes()
.checked_div(stride.bytes())
.unwrap_or(0),
_ => unreachable!(),
};

Expand Down
11 changes: 11 additions & 0 deletions tests/compiletests/ui/lang/core/mem/size_of_val_unsized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use spirv_std::spirv;

#[spirv(vertex)]
pub fn main(out: &mut usize) {
*out = core::mem::size_of_val(
const {
struct S<T: ?Sized>(T);
&S([]) as &S<[()]>
},
);
}
23 changes: 23 additions & 0 deletions tests/compiletests/ui/lang/core/mem/size_of_val_unsized.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error: unsupported unsized `[struct () { }]` constant
|
= note: used by unnamed global (%68)
= note: used by unnamed global (%69)
note: used from within `size_of_val_unsized::main`
--> <$DIR/size_of_val_unsized.rs>:5:12
|
LL | *out = core::mem::size_of_val(
| ____________^
LL | | const {
LL | | struct S<T: ?Sized>(T);
LL | | &S([]) as &S<[()]>
LL | | },
LL | | );
| |_____^
note: called by `main`
--> <$DIR/size_of_val_unsized.rs>:4:8
|
LL | pub fn main(out: &mut usize) {
| ^^^^

error: aborting due to 1 previous error

Comment on lines +1 to +23
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the patch is fine, saw the todo, moved it to a compiletest and it resulted in this interesting error

Loading