summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2023-03-17 15:07:22 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2023-03-17 16:15:58 -0400
commit2a26a5e677de61cdba04fc8df63c00d3c3e612a9 (patch)
tree4ed4d925e399b3c2a96e22f368bf4e608c70d4f8
parent5d0a1ffafa61da04dbda38a5cb5565bcb8032a78 (diff)
YJIT: Add and use Branch::assert_layout()
This assert would've caught a bug I wrote while developing ruby/ruby#7443 so I figured it would be good to commit it as it could be helpful in the future.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7558
-rw-r--r--yjit/src/core.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/yjit/src/core.rs b/yjit/src/core.rs
index c8c945fac3..334b037d4c 100644
--- a/yjit/src/core.rs
+++ b/yjit/src/core.rs
@@ -642,6 +642,16 @@ impl Branch {
}
count
}
+
+ fn assert_layout(&self) {
+ let shape = self.gen_fn.get_shape();
+ assert!(
+ !(shape == BranchShape::Default && 0 == self.code_size()),
+ "zero-size branches are incorrect when code for neither targets are adjacent"
+ // One needs to issue some instruction to steer to the branch target
+ // when falling through isn't an option.
+ );
+ }
}
impl std::fmt::Debug for Branch {
@@ -737,6 +747,8 @@ impl PendingBranch {
}
}
+ branch.assert_layout();
+
branchref
}
}
@@ -2248,6 +2260,8 @@ fn regenerate_branch(cb: &mut CodeBlock, branch: &Branch) {
// The branch sits at the end of cb and consumed some memory.
// Keep cb.write_pos.
}
+
+ branch.assert_layout();
}
pub type PendingBranchRef = Rc<PendingBranch>;