Skip to content

Commit 15db4ec

Browse files
committed
builder: special-case 0-byte-offset GEPs as pointer casts.
1 parent c94db24 commit 15db4ec

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
@@ -766,6 +766,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
766766

767767
// If we successfully calculated a constant byte offset for the first index...
768768
if let Some(const_ptr_offset_bytes) = const_ptr_offset_bytes {
769+
// HACK(eddyb) an offset of `0` is always a noop, and `pointercast`
770+
// gets to use `SpirvValueKind::LogicalPtrCast`, which can later
771+
// be "undone" (by `strip_ptrcasts`), allowing more flexibility
772+
// downstream (instead of overeagerly "shrinking" the pointee).
773+
if const_ptr_offset_bytes == 0 {
774+
return self.pointercast(ptr, final_spirv_ptr_type);
775+
}
776+
769777
// Try to reconstruct a more "structured" access chain based on the *original*
770778
// pointee type of the pointer (`original_pointee_ty`) and the calculated byte offset.
771779
// 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)