Skip to content

Commit 4f61d81

Browse files
committed
Allow int/ptr casts
1 parent 75d0495 commit 4f61d81

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
360360
}
361361

362362
fn zombie_convert_ptr_to_u(&self, def: Word) {
363-
self.zombie(def, "cannot convert pointers to integers");
363+
if !self
364+
.builder
365+
.has_capability(Capability::PhysicalStorageBufferAddresses)
366+
{
367+
self.zombie(def, "cannot convert pointers to integers without OpCapability PhysicalStorageBufferAddresses");
368+
}
364369
}
365370

366371
fn zombie_convert_u_to_ptr(&self, def: Word) {
367-
self.zombie(def, "cannot convert integers to pointers");
372+
if !self
373+
.builder
374+
.has_capability(Capability::PhysicalStorageBufferAddresses)
375+
{
376+
self.zombie(def, "cannot convert integers to pointers without OpCapability PhysicalStorageBufferAddresses");
377+
}
368378
}
369379

370380
fn zombie_ptr_equal(&self, def: Word, inst: &str) {
@@ -1752,20 +1762,23 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
17521762
}
17531763

17541764
fn inttoptr(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value {
1755-
match self.lookup_type(dest_ty) {
1756-
SpirvType::Pointer { .. } => (),
1765+
let result_ty = match self.lookup_type(dest_ty) {
1766+
SpirvType::Pointer { pointee, .. } => self.type_ptr_to_with_storage_class(
1767+
pointee,
1768+
StorageClassKind::Explicit(StorageClass::PhysicalStorageBuffer),
1769+
),
17571770
other => self.fatal(format!(
17581771
"inttoptr called on non-pointer dest type: {other:?}"
17591772
)),
1760-
}
1761-
if val.ty == dest_ty {
1773+
};
1774+
if val.ty == result_ty {
17621775
val
17631776
} else {
17641777
let result = self
17651778
.emit()
1766-
.convert_u_to_ptr(dest_ty, None, val.def(self))
1779+
.convert_u_to_ptr(result_ty, None, val.def(self))
17671780
.unwrap()
1768-
.with_type(dest_ty);
1781+
.with_type(result_ty);
17691782
self.zombie_convert_u_to_ptr(result.def(self));
17701783
result
17711784
}

0 commit comments

Comments
 (0)