Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not panic on ref types while safepoint disabled #1196

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions cranelift/codegen/src/regalloc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,18 @@ impl Context {
emit_stackmaps(func, domtree, &self.liveness, &mut self.tracker, isa);
} else {
// Make sure no references are used.
for val in func.dfg.values() {
let ty = func.dfg.value_type(val);
if ty.lane_type().is_ref() {
panic!("reference types were found but safepoints were not enabled.");
for block in func.layout.blocks() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using references as function parameters, but not using them anywhere? This would skip them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I think a few tests actually need to be added:

  • for function parameters
  • for EBB params
  • for value types in signature refs

Can you add the code and tests for this, please? Thanks!

for inst in func.layout.block_insts(block) {
for val in func.dfg.inst_results(inst) {
let ty = func.dfg.value_type(*val);
if ty.lane_type().is_ref() {
errors.report((
inst,
"reference types were found but safepoints were not enabled.",
));
return Err(errors.into());
}
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions cranelift/filetests/filetests/verifier/ref-safepoint.clif
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test verifier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error is reported during regalloc, not during the verifier pass.

target x86_64

function %test(r64) -> r64 {
block0(v0: r64):
v1 = null.r64
v2 = is_null v0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an error annotation in this test, so it'd check that the verifier asserts because a ref type is used yet ref types aren't enabled, right?

brz v2, block2(v0)
jump block2(v1)
block2(v3: r64):
return v3
}