making sure sliced pointer is loaded

Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
Jakub Doka 2024-12-22 18:53:52 +01:00
parent 9f67b22aa2
commit 5909837015
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
3 changed files with 24 additions and 2 deletions

View file

@ -798,6 +798,16 @@ main := fn(): uint {
### Purely Testing Examples
#### slice_to_global_pointer
```hb
a := @as(^u8, @bitcast(0))
main := fn(): ^u8 {
b := a[0..100]
return b.ptr
}
```
#### subsclice_bug
```hb
main := fn(): void {

View file

@ -1268,7 +1268,7 @@ impl<'a> Codegen<'a> {
}
}
Expr::Index { base, index: &Expr::Range { start, end, pos } } => {
let bs = self.ptr_expr(base)?;
let mut bs = self.ptr_expr(base)?;
let start = match start {
Some(s) => self.checked_expr(s, ty::Id::UINT, "range start")?.id,
@ -1325,7 +1325,10 @@ impl<'a> Codegen<'a> {
let base = self.tys.make_ptr(elem);
Value::new(self.load_mem(off, base)).ty(base)
}
ty::Kind::Ptr(_) => bs,
ty::Kind::Ptr(_) => {
self.strip_ptr(&mut bs);
bs
}
_ => unreachable!(),
};
ptr.id = self.offset_ptr(ptr.id, elem, start).id;
@ -4462,6 +4465,7 @@ mod tests {
fb_driver;
// Purely Testing Examples;
slice_to_global_pointer;
subsclice_bug;
string_array;
proper_ident_propagation;

View file

@ -0,0 +1,8 @@
main:
LRA r13, r0, :a
LD r13, r13, 0a, 8h
CP r1, r13
JALA r0, r31, 0a
code size: 50
ret: 0
status: Ok(())