diff --git a/lang/README.md b/lang/README.md index 93b3694f..241dd03b 100644 --- a/lang/README.md +++ b/lang/README.md @@ -493,28 +493,6 @@ main := fn(): never { ### Incomplete Examples -#### advanced_floating_point_arithmetic -```hb - -SIN_TABLE := [f32].(0.0, 0.02454122852291229, 0.04906767432741801, 0.07356456359966743, 0.0980171403295606, 0.1224106751992162, 0.1467304744553617, 0.1709618887603012, 0.1950903220161282, 0.2191012401568698, 0.2429801799032639, 0.2667127574748984, 0.2902846772544623, 0.3136817403988915, 0.3368898533922201, 0.3598950365349881, 0.3826834323650898, 0.4052413140049899, 0.4275550934302821, 0.4496113296546065, 0.4713967368259976, 0.492898192229784, 0.5141027441932217, 0.5349976198870972, 0.5555702330196022, 0.5758081914178453, 0.5956993044924334, 0.6152315905806268, 0.6343932841636455, 0.6531728429537768, 0.6715589548470183, 0.6895405447370668, 0.7071067811865475, 0.7242470829514669, 0.7409511253549591, 0.7572088465064845, 0.773010453362737, 0.7883464276266062, 0.8032075314806448, 0.8175848131515837, 0.8314696123025452, 0.844853565249707, 0.8577286100002721, 0.8700869911087113, 0.8819212643483549, 0.8932243011955153, 0.9039892931234433, 0.9142097557035307, 0.9238795325112867, 0.9329927988347388, 0.9415440651830208, 0.9495281805930367, 0.9569403357322089, 0.9637760657954398, 0.970031253194544, 0.9757021300385286, 0.9807852804032304, 0.9852776423889412, 0.989176509964781, 0.99247953459871, 0.9951847266721968, 0.9972904566786902, 0.9987954562051724, 0.9996988186962042, 1.0, 0.9996988186962042, 0.9987954562051724, 0.9972904566786902, 0.9951847266721969, 0.99247953459871, 0.989176509964781, 0.9852776423889412, 0.9807852804032304, 0.9757021300385286, 0.970031253194544, 0.9637760657954398, 0.9569403357322089, 0.9495281805930367, 0.9415440651830208, 0.9329927988347388, 0.9238795325112867, 0.9142097557035307, 0.9039892931234434, 0.8932243011955152, 0.881921264348355, 0.8700869911087115, 0.8577286100002721, 0.8448535652497072, 0.8314696123025455, 0.8175848131515837, 0.8032075314806449, 0.7883464276266063, 0.7730104533627371, 0.7572088465064847, 0.740951125354959, 0.7242470829514669, 0.7071067811865476, 0.6895405447370671, 0.6715589548470186, 0.6531728429537766, 0.6343932841636455, 0.6152315905806269, 0.5956993044924335, 0.5758081914178454, 0.5555702330196022, 0.5349976198870972, 0.5141027441932218, 0.4928981922297841, 0.4713967368259979, 0.4496113296546069, 0.427555093430282, 0.4052413140049899, 0.3826834323650899, 0.3598950365349883, 0.3368898533922203, 0.3136817403988914, 0.2902846772544624, 0.2667127574748985, 0.2429801799032641, 0.21910124015687, 0.1950903220161286, 0.1709618887603012, 0.1467304744553618, 0.1224106751992163, 0.09801714032956083, 0.07356456359966773, 0.04906767432741797, 0.02454122852291233, 0.0, -0.02454122852291208, -0.04906767432741772, -0.0735645635996675, -0.09801714032956059, -0.1224106751992161, -0.1467304744553616, -0.170961888760301, -0.1950903220161284, -0.2191012401568698, -0.2429801799032638, -0.2667127574748983, -0.2902846772544621, -0.3136817403988912, -0.3368898533922201, -0.3598950365349881, -0.3826834323650897, -0.4052413140049897, -0.4275550934302818, -0.4496113296546067, -0.4713967368259976, -0.4928981922297839, -0.5141027441932216, -0.5349976198870969, -0.555570233019602, -0.5758081914178453, -0.5956993044924332, -0.6152315905806267, -0.6343932841636453, -0.6531728429537765, -0.6715589548470184, -0.6895405447370668, -0.7071067811865475, -0.7242470829514668, -0.7409511253549589, -0.7572088465064842, -0.7730104533627367, -0.7883464276266059, -0.8032075314806451, -0.8175848131515838, -0.8314696123025452, -0.844853565249707, -0.857728610000272, -0.8700869911087113, -0.8819212643483549, -0.8932243011955152, -0.9039892931234431, -0.9142097557035305, -0.9238795325112865, -0.932992798834739, -0.9415440651830208, -0.9495281805930367, -0.9569403357322088, -0.9637760657954398, -0.970031253194544, -0.9757021300385285, -0.9807852804032303, -0.9852776423889411, -0.9891765099647809, -0.9924795345987101, -0.9951847266721969, -0.9972904566786902, -0.9987954562051724, -0.9996988186962042, -1.0, -0.9996988186962042, -0.9987954562051724, -0.9972904566786902, -0.9951847266721969, -0.9924795345987101, -0.9891765099647809, -0.9852776423889412, -0.9807852804032304, -0.9757021300385286, -0.970031253194544, -0.96377606579544, -0.9569403357322089, -0.9495281805930368, -0.9415440651830209, -0.9329927988347391, -0.9238795325112866, -0.9142097557035306, -0.9039892931234433, -0.8932243011955153, -0.881921264348355, -0.8700869911087115, -0.8577286100002722, -0.8448535652497072, -0.8314696123025455, -0.817584813151584, -0.8032075314806453, -0.7883464276266061, -0.7730104533627369, -0.7572088465064846, -0.7409511253549591, -0.724247082951467, -0.7071067811865477, -0.6895405447370672, -0.6715589548470187, -0.6531728429537771, -0.6343932841636459, -0.6152315905806274, -0.5956993044924332, -0.5758081914178452, -0.5555702330196022, -0.5349976198870973, -0.5141027441932219, -0.4928981922297843, -0.4713967368259979, -0.449611329654607, -0.4275550934302825, -0.4052413140049904, -0.3826834323650904, -0.359895036534988, -0.33688985339222, -0.3136817403988915, -0.2902846772544625, -0.2667127574748986, -0.2429801799032642, -0.2191012401568702, -0.1950903220161287, -0.1709618887603018, -0.1467304744553624, -0.122410675199216, -0.09801714032956051, -0.07356456359966741, -0.04906767432741809, -0.02454122852291245) - -sin := fn(theta: f32): f32 { - PI := 3.14159265358979323846 - TABLE_SIZE := @as(i32, 256) - si := @fti(theta * 0.5 * @itf(TABLE_SIZE) / PI) - d := theta - @floatcast(@itf(si)) * 2.0 * PI / @itf(TABLE_SIZE) - ci := si + TABLE_SIZE / 4 & TABLE_SIZE - 1 - si &= TABLE_SIZE - 1 - return SIN_TABLE[@bitcast(si)] + (SIN_TABLE[@bitcast(ci)] - 0.5 * SIN_TABLE[@bitcast(si)] * d) * d -} - -main := fn(): int { - // expected result: 826 - return @fti(sin(1000.0) * 1000.0) -} -``` - - #### comptime_pointers ```hb main := fn(): uint { @@ -634,6 +612,34 @@ main := fn(): uint { ### Purely Testing Examples +#### stack_provenance +```hb +main := fn(): uint { + return *dangle() +} +dangle := fn(): ^uint return &0 +``` + +#### advanced_floating_point_arithmetic +```hb +SIN_TABLE := [f32].(0.0, 0.02454122852291229, 0.04906767432741801, 0.07356456359966743, 0.0980171403295606, 0.1224106751992162, 0.1467304744553617, 0.1709618887603012, 0.1950903220161282, 0.2191012401568698, 0.2429801799032639, 0.2667127574748984, 0.2902846772544623, 0.3136817403988915, 0.3368898533922201, 0.3598950365349881, 0.3826834323650898, 0.4052413140049899, 0.4275550934302821, 0.4496113296546065, 0.4713967368259976, 0.492898192229784, 0.5141027441932217, 0.5349976198870972, 0.5555702330196022, 0.5758081914178453, 0.5956993044924334, 0.6152315905806268, 0.6343932841636455, 0.6531728429537768, 0.6715589548470183, 0.6895405447370668, 0.7071067811865475, 0.7242470829514669, 0.7409511253549591, 0.7572088465064845, 0.773010453362737, 0.7883464276266062, 0.8032075314806448, 0.8175848131515837, 0.8314696123025452, 0.844853565249707, 0.8577286100002721, 0.8700869911087113, 0.8819212643483549, 0.8932243011955153, 0.9039892931234433, 0.9142097557035307, 0.9238795325112867, 0.9329927988347388, 0.9415440651830208, 0.9495281805930367, 0.9569403357322089, 0.9637760657954398, 0.970031253194544, 0.9757021300385286, 0.9807852804032304, 0.9852776423889412, 0.989176509964781, 0.99247953459871, 0.9951847266721968, 0.9972904566786902, 0.9987954562051724, 0.9996988186962042, 1.0, 0.9996988186962042, 0.9987954562051724, 0.9972904566786902, 0.9951847266721969, 0.99247953459871, 0.989176509964781, 0.9852776423889412, 0.9807852804032304, 0.9757021300385286, 0.970031253194544, 0.9637760657954398, 0.9569403357322089, 0.9495281805930367, 0.9415440651830208, 0.9329927988347388, 0.9238795325112867, 0.9142097557035307, 0.9039892931234434, 0.8932243011955152, 0.881921264348355, 0.8700869911087115, 0.8577286100002721, 0.8448535652497072, 0.8314696123025455, 0.8175848131515837, 0.8032075314806449, 0.7883464276266063, 0.7730104533627371, 0.7572088465064847, 0.740951125354959, 0.7242470829514669, 0.7071067811865476, 0.6895405447370671, 0.6715589548470186, 0.6531728429537766, 0.6343932841636455, 0.6152315905806269, 0.5956993044924335, 0.5758081914178454, 0.5555702330196022, 0.5349976198870972, 0.5141027441932218, 0.4928981922297841, 0.4713967368259979, 0.4496113296546069, 0.427555093430282, 0.4052413140049899, 0.3826834323650899, 0.3598950365349883, 0.3368898533922203, 0.3136817403988914, 0.2902846772544624, 0.2667127574748985, 0.2429801799032641, 0.21910124015687, 0.1950903220161286, 0.1709618887603012, 0.1467304744553618, 0.1224106751992163, 0.09801714032956083, 0.07356456359966773, 0.04906767432741797, 0.02454122852291233, 0.0, -0.02454122852291208, -0.04906767432741772, -0.0735645635996675, -0.09801714032956059, -0.1224106751992161, -0.1467304744553616, -0.170961888760301, -0.1950903220161284, -0.2191012401568698, -0.2429801799032638, -0.2667127574748983, -0.2902846772544621, -0.3136817403988912, -0.3368898533922201, -0.3598950365349881, -0.3826834323650897, -0.4052413140049897, -0.4275550934302818, -0.4496113296546067, -0.4713967368259976, -0.4928981922297839, -0.5141027441932216, -0.5349976198870969, -0.555570233019602, -0.5758081914178453, -0.5956993044924332, -0.6152315905806267, -0.6343932841636453, -0.6531728429537765, -0.6715589548470184, -0.6895405447370668, -0.7071067811865475, -0.7242470829514668, -0.7409511253549589, -0.7572088465064842, -0.7730104533627367, -0.7883464276266059, -0.8032075314806451, -0.8175848131515838, -0.8314696123025452, -0.844853565249707, -0.857728610000272, -0.8700869911087113, -0.8819212643483549, -0.8932243011955152, -0.9039892931234431, -0.9142097557035305, -0.9238795325112865, -0.932992798834739, -0.9415440651830208, -0.9495281805930367, -0.9569403357322088, -0.9637760657954398, -0.970031253194544, -0.9757021300385285, -0.9807852804032303, -0.9852776423889411, -0.9891765099647809, -0.9924795345987101, -0.9951847266721969, -0.9972904566786902, -0.9987954562051724, -0.9996988186962042, -1.0, -0.9996988186962042, -0.9987954562051724, -0.9972904566786902, -0.9951847266721969, -0.9924795345987101, -0.9891765099647809, -0.9852776423889412, -0.9807852804032304, -0.9757021300385286, -0.970031253194544, -0.96377606579544, -0.9569403357322089, -0.9495281805930368, -0.9415440651830209, -0.9329927988347391, -0.9238795325112866, -0.9142097557035306, -0.9039892931234433, -0.8932243011955153, -0.881921264348355, -0.8700869911087115, -0.8577286100002722, -0.8448535652497072, -0.8314696123025455, -0.817584813151584, -0.8032075314806453, -0.7883464276266061, -0.7730104533627369, -0.7572088465064846, -0.7409511253549591, -0.724247082951467, -0.7071067811865477, -0.6895405447370672, -0.6715589548470187, -0.6531728429537771, -0.6343932841636459, -0.6152315905806274, -0.5956993044924332, -0.5758081914178452, -0.5555702330196022, -0.5349976198870973, -0.5141027441932219, -0.4928981922297843, -0.4713967368259979, -0.449611329654607, -0.4275550934302825, -0.4052413140049904, -0.3826834323650904, -0.359895036534988, -0.33688985339222, -0.3136817403988915, -0.2902846772544625, -0.2667127574748986, -0.2429801799032642, -0.2191012401568702, -0.1950903220161287, -0.1709618887603018, -0.1467304744553624, -0.122410675199216, -0.09801714032956051, -0.07356456359966741, -0.04906767432741809, -0.02454122852291245) + +sin := fn(theta: f32): f32 { + PI := 3.14159265358979323846 + TABLE_SIZE := @as(i32, 256) + si := @fti(theta * 0.5 * @itf(TABLE_SIZE) / PI) + d := theta - @floatcast(@itf(si)) * 2.0 * PI / @itf(TABLE_SIZE) + ci := si + TABLE_SIZE / 4 & TABLE_SIZE - 1 + si &= TABLE_SIZE - 1 + return SIN_TABLE[@bitcast(si)] + (SIN_TABLE[@bitcast(ci)] - 0.5 * SIN_TABLE[@bitcast(si)] * d) * d +} + +main := fn(): int { + // expected result: 826 + return @fti(sin(1000.0) * 1000.0) +} +``` + #### nullable_structure ```hb Structure := struct {} @@ -1211,10 +1217,7 @@ main := fn(): uint { #### null_check_test ```hb -get_ptr := fn(): ?^uint { - value := 0 - return &value -} +get_ptr := fn(): ?^uint return null main := fn(): uint { ptr := get_ptr() diff --git a/lang/src/son.rs b/lang/src/son.rs index 18a1af07..7e126e45 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -994,6 +994,14 @@ impl Nodes { continue; } + if self[class.1].outputs.iter().any(|&n| { + self[n].kind != Kind::Stre + && self[n].outputs.iter().any(|&n| self[n].kind != Kind::Stre) + }) { + new_inps.push(n); + continue; + } + cursor = self[cursor].inputs[3]; while cursor != MEM { debug_assert_eq!(self[cursor].kind, Kind::Stre); @@ -1799,6 +1807,7 @@ pub struct Node { loop_depth: Cell, aclass: AClassId, antidep: Nid, + pos: Pos, } impl Node { @@ -2318,9 +2327,10 @@ impl<'a> Codegen<'a> { self.ct.run(ret_loc, entry) } - fn new_stack(&mut self, ty: ty::Id) -> Nid { + fn new_stack(&mut self, pos: Pos, ty: ty::Id) -> Nid { let stck = self.ci.nodes.new_node_nop(ty, Kind::Stck, [VOID, MEM]); self.ci.nodes[stck].aclass = self.ci.scope.aclasses.len() as _; + self.ci.nodes[stck].pos = pos; self.ci.scope.aclasses.push(AClass::new(&mut self.ci.nodes)); stck } @@ -2452,7 +2462,7 @@ impl<'a> Codegen<'a> { Loc::Reg => Some(self.ci.nodes.new_const_lit(oty, 0)), Loc::Stack => { let OptLayout { flag_ty, flag_offset, .. } = self.tys.opt_layout(ty); - let stack = self.new_stack(oty); + let stack = self.new_stack(pos, oty); let offset = self.offset(stack, flag_offset); let value = self.ci.nodes.new_const(flag_ty, 0); self.store_mem(offset, flag_ty, value); @@ -2464,7 +2474,7 @@ impl<'a> Codegen<'a> { inference!(ty, ctx, self, pos, "value", "@as(, idk)"); if ty.loc(self.tys) == Loc::Stack { - Some(Value::ptr(self.new_stack(ty)).ty(ty)) + Some(Value::ptr(self.new_stack(pos, ty)).ty(ty)) } else { Some(self.ci.nodes.new_const_lit(ty, 0)) } @@ -2562,6 +2572,8 @@ impl<'a> Codegen<'a> { &mut self.ci.nodes, ); + self.ci.nodes[self.ci.ctrl.get()].pos = pos; + self.ci.nodes[NEVER].inputs.push(self.ci.ctrl.get()); self.ci.nodes[self.ci.ctrl.get()].outputs.push(NEVER); } else if let Some((pv, ctrl, scope)) = &mut self.ci.inline_ret { @@ -2661,7 +2673,7 @@ impl<'a> Codegen<'a> { Some(Value::ptr(self.offset(vtarget.id, offset)).ty(ty)) } - Expr::UnOp { op: TokenKind::Band, val, .. } => { + Expr::UnOp { op: TokenKind::Band, val, pos } => { let ctx = Ctx { ty: ctx.ty.and_then(|ty| self.tys.base_of(ty)) }; let mut val = self.raw_expr_ctx(val, ctx)?; @@ -2673,7 +2685,7 @@ impl<'a> Codegen<'a> { return Some(val); } - let stack = self.new_stack(val.ty); + let stack = self.new_stack(pos, val.ty); self.store_mem(stack, val.ty, val.id); Some(Value::new(stack).ty(self.tys.make_ptr(val.ty))) @@ -2710,11 +2722,11 @@ impl<'a> Codegen<'a> { Value::NEVER } } - Expr::BinOp { left, op: TokenKind::Decl, right, .. } => { + Expr::BinOp { left, op: TokenKind::Decl, right, pos } => { let mut right = self.expr(right)?; if right.ty.loc(self.tys) == Loc::Stack { - let stck = self.new_stack(right.ty); + let stck = self.new_stack(pos, right.ty); self.store_mem(stck, right.ty, right.id); right.id = stck; right.ptr = true; @@ -2807,7 +2819,7 @@ impl<'a> Codegen<'a> { let mut rhs = rhs?; self.strip_var(&mut rhs); self.assert_ty(pos, &mut rhs, lhs.ty, "struct operand"); - let dst = self.new_stack(lhs.ty); + let dst = self.new_stack(pos, lhs.ty); self.struct_op(left.pos(), op, s, dst, lhs.id, rhs.id); Some(Value::ptr(dst).ty(lhs.ty)) } @@ -2906,7 +2918,7 @@ impl<'a> Codegen<'a> { match ty.loc(self.tys) { Loc::Reg if mem::take(&mut val.ptr) => val.id = self.load_mem(val.id, ty), Loc::Stack if !val.ptr => { - let stack = self.new_stack(ty); + let stack = self.new_stack(pos, ty); self.store_mem(stack, val.ty, val.id); val.id = stack; val.ptr = true; @@ -3074,7 +3086,7 @@ impl<'a> Codegen<'a> { let alt_value = match ty.loc(self.tys) { Loc::Reg => None, Loc::Stack => { - let stck = self.new_stack(ty); + let stck = self.new_stack(pos, ty); inps.push(stck); Some(Value::ptr(stck).ty(ty)) } @@ -3151,7 +3163,7 @@ impl<'a> Codegen<'a> { let alt_value = match sig.ret.loc(self.tys) { Loc::Reg => None, Loc::Stack => { - let stck = self.new_stack(sig.ret); + let stck = self.new_stack(func.pos(), sig.ret); inps.push(stck); Some(Value::ptr(stck).ty(sig.ret)) } @@ -3298,7 +3310,7 @@ impl<'a> Codegen<'a> { match sty.expand() { ty::Kind::Struct(s) => { - let mem = self.new_stack(sty); + let mem = self.new_stack(pos, sty); let mut offs = OffsetIter::new(s, self.tys); for field in fields { let Some((ty, offset)) = offs.next_ty(self.tys) else { @@ -3352,7 +3364,7 @@ impl<'a> Codegen<'a> { return Value::NEVER; } - let mem = self.new_stack(aty); + let mem = self.new_stack(pos, aty); for (field, offset) in fields.iter().zip((0u32..).step_by(elem_size as usize)) @@ -3407,7 +3419,7 @@ impl<'a> Codegen<'a> { .into_iter(self.tys) .map(|(f, o)| (f.ty, o)) .collect::>(); - let mem = self.new_stack(sty); + let mem = self.new_stack(pos, sty); for field in fields { let Some(index) = self.tys.find_struct_field(s, field.name) else { self.report( @@ -4199,6 +4211,23 @@ impl<'a> Codegen<'a> { self.ci.unlock(); + for &node in self.ci.nodes[NEVER].inputs.iter() { + if self.ci.nodes[node].kind == Kind::Return + && self.ci.nodes[self.ci.nodes.aclass_index(self.ci.nodes[node].inputs[1]).1].kind + == Kind::Stck + { + self.report( + self.ci.nodes[node].pos, + "returning value with local provenance \ + (pointer will be invalid after function returns)", + ); + self.report( + self.ci.nodes[self.ci.nodes.aclass_index(self.ci.nodes[node].inputs[1]).1].pos, + "...the pointer points to stack allocation created here", + ); + } + } + if self.errors.borrow().len() == prev_err_len { self.ci.nodes.check_final_integrity(self.ty_display(ty::Id::VOID)); self.ci.nodes.graphviz(self.ty_display(ty::Id::VOID)); @@ -4265,7 +4294,7 @@ impl<'a> Codegen<'a> { } } - fn wrap_in_opt(&mut self, val: &mut Value) { + fn wrap_in_opt(&mut self, pos: Pos, val: &mut Value) { debug_assert!(!val.var); let was_ptr = val.ptr; @@ -4294,7 +4323,7 @@ impl<'a> Codegen<'a> { } Loc::Stack => { self.strip_ptr(val); - let stack = self.new_stack(oty); + let stack = self.new_stack(pos, oty); let fill = self.ci.nodes.new_const(flag_ty, 1); self.store_mem(stack, flag_ty, fill); let off = self.offset(stack, payload_offset); @@ -4394,7 +4423,7 @@ impl<'a> Codegen<'a> { if inner != src.ty { self.assert_ty(pos, src, inner, hint); } - self.wrap_in_opt(src); + self.wrap_in_opt(pos, src); } else { debug_assert!( src.ty.is_integer() || src.ty == ty::Id::NEVER, @@ -4609,6 +4638,7 @@ mod tests { fb_driver; // Purely Testing Examples; + stack_provenance; advanced_floating_point_arithmetic; nullable_structure; needless_unwrap; diff --git a/lang/tests/son_tests_null_check_test.txt b/lang/tests/son_tests_null_check_test.txt index dc240719..883264a3 100644 --- a/lang/tests/son_tests_null_check_test.txt +++ b/lang/tests/son_tests_null_check_test.txt @@ -1,7 +1,5 @@ get_ptr: - ADDI64 r254, r254, -8d - ADDI64 r1, r254, 0d - ADDI64 r254, r254, 8d + LI64 r1, 0d JALA r0, r31, 0a main: ADDI64 r254, r254, -40d @@ -21,6 +19,6 @@ main: 1: LD r31, r254, 0a, 40h ADDI64 r254, r254, 40d JALA r0, r31, 0a -code size: 208 -ret: 10 +code size: 185 +ret: 0 status: Ok(()) diff --git a/lang/tests/son_tests_nullable_types.txt b/lang/tests/son_tests_nullable_types.txt index c5044256..e82d09ac 100644 --- a/lang/tests/son_tests_nullable_types.txt +++ b/lang/tests/son_tests_nullable_types.txt @@ -2,8 +2,8 @@ decide: LI8 r1, 1b JALA r0, r31, 0a main: - ADDI64 r254, r254, -224d - ST r31, r254, 80a, 144h + ADDI64 r254, r254, -232d + ST r31, r254, 80a, 152h JAL r31, r0, :decide LI64 r32, 0d ADDI64 r2, r254, 72d @@ -13,52 +13,54 @@ main: CP r34, r32 JMP :1 0: CP r34, r33 - 1: JNE r34, r32, :2 + 1: LI64 r35, 1d + ST r35, r254, 72a, 8h + JNE r34, r32, :2 LI64 r1, 9001d JMP :3 2: JAL r31, r0, :decide - LI8 r35, 0b + LI8 r36, 0b ANDI r1, r1, 255d JNE r1, r0, :4 - LI8 r36, 1b - ST r36, r254, 56a, 1h - LD r36, r34, 0a, 8h - ST r36, r254, 64a, 8h + LI8 r37, 1b + ST r37, r254, 56a, 1h + LD r37, r34, 0a, 8h + ST r37, r254, 64a, 8h JMP :5 - 4: ST r35, r254, 56a, 1h - 5: LD r37, r254, 56a, 1h - ANDI r37, r37, 255d - ANDI r35, r35, 255d - JEQ r37, r35, :6 + 4: ST r36, r254, 56a, 1h + 5: LD r38, r254, 56a, 1h + ANDI r38, r38, 255d + ANDI r36, r36, 255d + JEQ r38, r36, :6 LI64 r1, 42d JMP :3 6: JAL r31, r0, :decide - LI32 r38, 0w + LI32 r39, 0w ANDI r1, r1, 255d JNE r1, r0, :7 - CP r39, r38 + CP r40, r39 JMP :8 - 7: LI32 r39, 2147483649w - 8: ANDI r39, r39, 4294967295d - ANDI r38, r38, 4294967295d - JNE r39, r38, :9 + 7: LI32 r40, 2147483649w + 8: ANDI r40, r40, 4294967295d + ANDI r39, r39, 4294967295d + JNE r40, r39, :9 LI64 r1, 69d JMP :3 9: ADDI64 r3, r254, 40d - CP r40, r3 + CP r41, r3 JAL r31, r0, :new_foo ST r1, r254, 40a, 16h - LI64 r32, 0d - LD r41, r254, 40a, 8h - JNE r41, r32, :10 + LI64 r42, 0d + LD r43, r254, 40a, 8h + JNE r43, r42, :10 LI64 r1, 999d JMP :3 10: LRA r4, r0, :"foo\0" - CP r3, r40 + CP r3, r41 CP r2, r3 LD r2, r2, 0a, 16h JAL r31, r0, :use_foo - ADDI64 r42, r254, 0d + ADDI64 r44, r254, 0d JAL r31, r0, :no_foo ST r1, r254, 0a, 16h JAL r31, r0, :decide @@ -68,11 +70,9 @@ main: JMP :12 11: CP r2, r33 ST r2, r254, 0a, 8h - LI64 r43, 1d - ST r43, r254, 8a, 8h - ST r43, r254, 72a, 8h -12: LD r44, r254, 0a, 8h - JNE r44, r32, :13 + ST r35, r254, 8a, 8h +12: LD r45, r254, 0a, 8h + JNE r45, r42, :13 LI64 r1, 34d JMP :3 13: ADDI64 r1, r254, 16d @@ -81,19 +81,19 @@ main: ANDI r1, r1, 255d JNE r1, r0, :14 JMP :15 -14: ST r35, r254, 16a, 1h -15: LD r45, r254, 16a, 1h - ANDI r45, r45, 255d - ANDI r35, r35, 255d - JEQ r45, r35, :16 +14: ST r36, r254, 16a, 1h +15: LD r46, r254, 16a, 1h + ANDI r46, r46, 255d + ANDI r36, r36, 255d + JEQ r46, r36, :16 LI64 r1, 420d JMP :3 -16: LD r46, r254, 0a, 8h - LD r47, r46, 0a, 8h - ANDI r48, r39, 65535d - SUB64 r1, r48, r47 - 3: LD r31, r254, 80a, 144h - ADDI64 r254, r254, 224d +16: LD r47, r254, 0a, 8h + LD r48, r47, 0a, 8h + ANDI r49, r40, 65535d + SUB64 r1, r49, r48 + 3: LD r31, r254, 80a, 152h + ADDI64 r254, r254, 232d JALA r0, r31, 0a new_bar: ADDI64 r254, r254, -24d diff --git a/lang/tests/son_tests_stack_provenance.txt b/lang/tests/son_tests_stack_provenance.txt new file mode 100644 index 00000000..21ac4092 --- /dev/null +++ b/lang/tests/son_tests_stack_provenance.txt @@ -0,0 +1,6 @@ +test.hb:5:23: returning value with local provenance (pointer will be invalid after function returns) +dangle := fn(): ^uint return &0 + ^ +test.hb:5:30: ...the pointer points to stack allocation created here +dangle := fn(): ^uint return &0 + ^