Skip to content

Commit 25a0a0b

Browse files
authored
Cranelift: riscv64: fix instruction worst-case-length checks. (#10555)
In #10502, we introduced changes that could make callsites be arbitrarily long, because they now include loads of return-values-on-stack. We made use of the existing island mechanism (now presented as a new pseudoinst as in aarch64, rather than as ad-hoc emission code) to ensure that we meet label-reference-distance deadlines. Unfortunately we didn't update the debug-assert that checks instructions for worst-case size to exclude calls (and the new `EmitIsland` pseudoinst), since they handle islanding separately. Found via fuzzbug at [1]. [1]: https://oss-fuzz.com/testcase-detail/4819793142415360
1 parent d52e23b commit 25a0a0b

File tree

1 file changed

+13
-6
lines changed
  • cranelift/codegen/src/isa/riscv64/inst

1 file changed

+13
-6
lines changed

cranelift/codegen/src/isa/riscv64/inst/emit.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,19 @@ impl MachInstEmit for Inst {
246246
self.emit_uncompressed(sink, emit_info, state, &mut start_off);
247247
}
248248

249-
// We exclude br_table and return call from these checks since they emit
250-
// their own islands, and thus are allowed to exceed the worst case size.
251-
if !matches!(
252-
self,
253-
Inst::BrTable { .. } | Inst::ReturnCall { .. } | Inst::ReturnCallInd { .. }
254-
) {
249+
// We exclude br_table, call, return_call and try_call from
250+
// these checks since they emit their own islands, and thus
251+
// are allowed to exceed the worst case size.
252+
let emits_own_island = match self {
253+
Inst::BrTable { .. }
254+
| Inst::ReturnCall { .. }
255+
| Inst::ReturnCallInd { .. }
256+
| Inst::Call { .. }
257+
| Inst::CallInd { .. }
258+
| Inst::EmitIsland { .. } => true,
259+
_ => false,
260+
};
261+
if !emits_own_island {
255262
let end_off = sink.cur_offset();
256263
assert!(
257264
(end_off - start_off) <= Inst::worst_case_size(),

0 commit comments

Comments
 (0)