Skip to content

Commit 53307fd

Browse files
committed
Introduce PointerBase::Dangling
1 parent dfb5d16 commit 53307fd

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/abi/comments.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ pub(super) fn add_local_place_comments<'tcx>(
9090
(crate::pointer::PointerBase::Stack(stack_slot), offset) => {
9191
("stack", format!("storage={}{}{}", stack_slot, offset, meta).into())
9292
}
93+
(crate::pointer::PointerBase::Dangling(align), offset) => {
94+
("zst", format!("align={},offset={}", align.bytes(), offset).into())
95+
}
9396
}
9497
}
9598
};

src/pointer.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::prelude::*;
22

3+
use rustc_target::abi::Align;
4+
35
use cranelift_codegen::ir::immediates::Offset32;
46

57
#[derive(Copy, Clone, Debug)]
@@ -12,6 +14,7 @@ pub(crate) struct Pointer {
1214
pub(crate) enum PointerBase {
1315
Addr(Value),
1416
Stack(StackSlot),
17+
Dangling(Align),
1518
}
1619

1720
impl Pointer {
@@ -37,6 +40,13 @@ impl Pointer {
3740
}
3841
}
3942

43+
pub(crate) fn dangling(align: Align) -> Self {
44+
Pointer {
45+
base: PointerBase::Dangling(align),
46+
offset: Offset32::new(0),
47+
}
48+
}
49+
4050
#[cfg(debug_assertions)]
4151
pub(crate) fn base_and_offset(self) -> (PointerBase, Offset32) {
4252
(self.base, self.offset)
@@ -53,6 +63,9 @@ impl Pointer {
5363
}
5464
}
5565
PointerBase::Stack(stack_slot) => fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, self.offset),
66+
PointerBase::Dangling(align) => {
67+
fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(align.bytes()).unwrap())
68+
}
5669
}
5770
}
5871

@@ -80,6 +93,7 @@ impl Pointer {
8093
let base_addr = match self.base {
8194
PointerBase::Addr(addr) => addr,
8295
PointerBase::Stack(stack_slot) => fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0),
96+
PointerBase::Dangling(align) => fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(align.bytes()).unwrap()),
8397
};
8498
let addr = fx.bcx.ins().iadd_imm(base_addr, new_offset);
8599
Pointer {
@@ -109,6 +123,13 @@ impl Pointer {
109123
offset: Offset32::new(0),
110124
}
111125
}
126+
PointerBase::Dangling(align) => {
127+
let addr = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(align.bytes()).unwrap());
128+
Pointer {
129+
base: PointerBase::Addr(fx.bcx.ins().iadd(addr, extra_offset)),
130+
offset: self.offset,
131+
}
132+
}
112133
}
113134
}
114135

@@ -127,6 +148,7 @@ impl Pointer {
127148
} else {
128149
fx.bcx.ins().stack_load(ty, stack_slot, self.offset)
129150
}
151+
PointerBase::Dangling(_align) => unreachable!(),
130152
}
131153
}
132154

@@ -150,6 +172,7 @@ impl Pointer {
150172
fx.bcx.ins().stack_store(value, stack_slot, self.offset);
151173
}
152174
}
175+
PointerBase::Dangling(_align) => unreachable!(),
153176
}
154177
}
155178
}

src/value_and_place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<'tcx> CPlace<'tcx> {
344344
}
345345
}
346346
CPlaceInner::NoPlace => CValue::by_ref(
347-
Pointer::const_addr(fx, i64::try_from(self.layout.align.pref.bytes()).unwrap()),
347+
Pointer::dangling(self.layout.align.pref),
348348
layout,
349349
),
350350
}

0 commit comments

Comments
 (0)