Skip to content

Commit b16328f

Browse files
committed
builder: special-case 0-byte-offset GEPs as pointer casts.
1 parent 4738965 commit b16328f

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
767767

768768
// If we successfully calculated a constant byte offset for the first index...
769769
if let Some(const_ptr_offset_bytes) = const_ptr_offset_bytes {
770+
// HACK(eddyb) an offset of `0` is always a noop, and `pointercast`
771+
// gets to use `SpirvValueKind::LogicalPtrCast`, which can later
772+
// be "undone" (by `strip_ptrcasts`), allowing more flexibility
773+
// downstream (instead of overeagerly "shrinking" the pointee).
774+
if const_ptr_offset_bytes == 0 {
775+
return self.pointercast(ptr, final_spirv_ptr_type);
776+
}
777+
770778
// Try to reconstruct a more "structured" access chain based on the *original*
771779
// pointee type of the pointer (`original_pointee_ty`) and the calculated byte offset.
772780
// This is useful if the input `ty` was generic (like u8) but the pointer actually

tests/compiletests/ui/lang/issue-46.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/compiletests/ui/storage_class/typed-buffer-simple.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)