Skip to content

Commit

Permalink
MachInst backend: attach SourceLoc span information to all ranges.
Browse files Browse the repository at this point in the history
Previously, the SourceLoc information transferred in `VCode` only
included PC-spans for non-default SourceLocs. I realized that the
invariant we're supposed to keep here is that every PC is covered; if no
source information, just use `SourceLoc::default()`.

This was spurred by @bjorn3's comment in bytecodealliance#1575 (thanks!).
  • Loading branch information
cfallin committed Apr 29, 2020
1 parent 738e274 commit ec86dba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
16 changes: 7 additions & 9 deletions cranelift/codegen/src/machinst/vcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ impl<I: VCodeInst> VCode<I> {
let code_section = sections.get_section(code_idx);

let flags = self.abi.flags();
let mut cur_srcloc = SourceLoc::default();
let mut cur_srcloc = None;
for &block in &self.final_block_order {
let new_offset = I::align_basic_block(code_section.cur_offset_from_start());
while new_offset > code_section.cur_offset_from_start() {
Expand All @@ -563,22 +563,20 @@ impl<I: VCodeInst> VCode<I> {
let (start, end) = self.block_ranges[block as usize];
for iix in start..end {
let srcloc = self.srclocs[iix as usize];
if srcloc != cur_srcloc {
if !cur_srcloc.is_default() {
if Some(srcloc) != cur_srcloc {
if cur_srcloc.is_some() {
code_section.end_srcloc();
}
if !srcloc.is_default() {
code_section.start_srcloc(srcloc);
}
cur_srcloc = srcloc;
code_section.start_srcloc(srcloc);
cur_srcloc = Some(srcloc);
}

self.insts[iix as usize].emit(code_section, flags);
}

if !cur_srcloc.is_default() {
if cur_srcloc.is_some() {
code_section.end_srcloc();
cur_srcloc = SourceLoc::default();
cur_srcloc = None;
}
}

Expand Down
6 changes: 1 addition & 5 deletions crates/api/src/frame_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ impl GlobalFrameInfo {
// the function, because otherwise something is buggy along the way and
// not accounting for all the instructions. This isn't super critical
// though so we can omit this check in release mode.
//
// FIXME(#1521) aarch64 instruction info isn't quite up-to-par yet.
if !cfg!(target_arch = "aarch64") {
debug_assert!(pos.is_some(), "failed to find instruction for {:x}", pc);
}
debug_assert!(pos.is_some(), "failed to find instruction for {:x}", pc);

let instr = match pos {
Some(pos) => func.instr_map.instructions[pos].srcloc,
Expand Down

0 comments on commit ec86dba

Please sign in to comment.