From 2a26a5e677de61cdba04fc8df63c00d3c3e612a9 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Fri, 17 Mar 2023 15:07:22 -0400 Subject: [PATCH] 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. --- yjit/src/core.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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;