Skip to content

Commit a282368

Browse files
committed
builder: special-case 0-byte-offset GEPs as pointer casts.
1 parent 02701d2 commit a282368

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

818818
// If we successfully calculated a constant byte offset for the first index...
819819
if let Some(const_ptr_offset_bytes) = const_ptr_offset_bytes {
820+
// HACK(eddyb) an offset of `0` is always a noop, and `pointercast`
821+
// gets to use `SpirvValueKind::LogicalPtrCast`, which can later
822+
// be "undone" (by `strip_ptrcasts`), allowing more flexibility
823+
// downstream (instead of overeagerly "shrinking" the pointee).
824+
if const_ptr_offset_bytes == 0 {
825+
return self.pointercast(ptr, final_spirv_ptr_type);
826+
}
827+
820828
// Try to reconstruct a more "structured" access chain based on the *original*
821829
// pointee type of the pointer (`original_pointee_ty`) and the calculated byte offset.
822830
// 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)