From e89511b14cdfd5694e90bf704a6853c67e8dde68 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sun, 17 Nov 2024 22:26:31 +0100 Subject: [PATCH] fixing position reporting for optimized returns --- lang/src/son.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lang/src/son.rs b/lang/src/son.rs index 708554a4..fe102504 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -24,7 +24,6 @@ use { fmt::{self, Debug, Display, Write}, format_args as fa, mem, ops::{self, Range}, - usize, }, hashbrown::hash_map, hbbytecode::DisasmError, @@ -1066,7 +1065,9 @@ impl Nodes { } if new_inps.as_slice() != self[target].inputs.as_slice() { - return Some(self.new_node_nop(ty::Id::VOID, Kind::Return { file }, new_inps)); + let ret = self.new_node_nop(ty::Id::VOID, Kind::Return { file }, new_inps); + self[ret].pos = self[target].pos; + return Some(ret); } } K::Phi => { @@ -2793,11 +2794,6 @@ impl<'a> Codegen<'a> { } } - debug_assert_eq!( - lexer::Lexer::new(&self.file().file[pos as usize..]).eat().kind, - TokenKind::Return - ); - let ret = self.ci.nodes.new_node_nop( ty::Id::VOID, Kind::Return { file: self.ci.file }, @@ -4712,17 +4708,18 @@ impl<'a> Codegen<'a> { for &node in self.ci.nodes[NEVER].inputs.iter() { if let Kind::Return { file } = self.ci.nodes[node].kind - && self.ci.nodes[self.ci.nodes.aclass_index(self.ci.nodes[node].inputs[1]).1].kind - == Kind::Stck + && let (_, stck) = self.ci.nodes.aclass_index(self.ci.nodes[node].inputs[1]) + && self.ci.nodes[stck].kind == Kind::Stck { let pfile = mem::replace(&mut self.ci.file, file); + debug_assert!(self.ci.nodes[node].pos != 0); self.error( self.ci.nodes[node].pos, "returning value with local provenance \ (pointer will be invalid after function returns)", ); self.error( - self.ci.nodes[self.ci.nodes.aclass_index(self.ci.nodes[node].inputs[1]).1].pos, + self.ci.nodes[stck].pos, "...the pointer points to stack allocation created here", ); self.ci.file = pfile;