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;