Fix updating srclocs in truncate_last_branch
The truncate_last_branch removes an instruction that had already been added to the buffer, and must update various bookkeeping. However, updating the "srclocs" field is incorrect: if there is a srclocs entry that spans both the removed branch *and some previous instruction*, that whole srclocs entry is removed, which makes those previous instructions now uncovered by any srclocs record. This can cause subsequent problems e.g. if one of those instructions traps. Fixed by just truncating instead of fully removing the srclocs record in this case.
This commit is contained in:
@@ -680,10 +680,14 @@ impl<I: VCodeInst> MachBuffer<I> {
|
||||
// (end of buffer)
|
||||
self.data.truncate(b.start as usize);
|
||||
self.fixup_records.truncate(b.fixup);
|
||||
while let Some(last_srcloc) = self.srclocs.last() {
|
||||
while let Some(mut last_srcloc) = self.srclocs.last_mut() {
|
||||
if last_srcloc.end <= b.start {
|
||||
break;
|
||||
}
|
||||
if last_srcloc.start < b.start {
|
||||
last_srcloc.end = b.start;
|
||||
break;
|
||||
}
|
||||
self.srclocs.pop();
|
||||
}
|
||||
// State:
|
||||
|
||||
Reference in New Issue
Block a user