fixing position reporting for optimized returns

This commit is contained in:
Jakub Doka 2024-11-17 22:26:31 +01:00
parent 1c135a3050
commit e89511b14c
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143

View file

@ -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;