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

smith: Fix types recorded in ref.func #1965

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
with:
submodules: true
- uses: ./.github/actions/install-rust
- uses: bytecodealliance/wasmtime/.github/actions/binary-compatible-builds@main
- uses: bytecodealliance/wasmtime/.github/actions/binary-compatible-builds@release-28.0.0
with:
name: ${{ matrix.build }}
if: matrix.build != 'wasm32-wasip1'
Expand Down
19 changes: 17 additions & 2 deletions crates/wasm-smith/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ impl Module {
}

fn arbitrary_super_type_of_val_type(
&mut self,
&self,
u: &mut Unstructured,
ty: ValType,
) -> Result<ValType> {
Expand Down Expand Up @@ -938,8 +938,23 @@ impl Module {
) -> Result<HeapType> {
use {AbstractHeapType as AHT, CompositeInnerType as CT, HeapType as HT};

// If GC is disabled then favor the "top" type of the input type.
if !self.config.gc_enabled {
return Ok(ty);
return Ok(match ty {
HeapType::Concrete(i) => {
let CompositeType { inner, shared } = &self.ty(i).composite_type;
let ty = match inner {
CompositeInnerType::Array(_) => AbstractHeapType::Array,
CompositeInnerType::Struct(_) => AbstractHeapType::Struct,
CompositeInnerType::Func(_) => AbstractHeapType::Func,
};
HeapType::Abstract {
shared: *shared,
ty,
}
}
HeapType::Abstract { .. } => ty,
});
}

let mut choices = vec![ty];
Expand Down
37 changes: 20 additions & 17 deletions crates/wasm-smith/src/core/code_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2654,21 +2654,28 @@ fn select_valid(module: &Module, builder: &mut CodeBuilder) -> bool {
}

fn select(
_: &mut Unstructured,
_module: &Module,
u: &mut Unstructured,
module: &Module,
builder: &mut CodeBuilder,
instructions: &mut Vec<Instruction>,
) -> Result<()> {
builder.pop_operand();
let t = builder.pop_operand();
let u = builder.pop_operand();
let ty = t.or(u);
builder.allocs.operands.push(ty);
match ty {
Some(ty @ ValType::Ref(_)) => instructions.push(Instruction::TypedSelect(ty)),
let a = builder.pop_operand();
let b = builder.pop_operand();
let ty = a.or(b);
let ty = match ty {
Some(ty @ ValType::Ref(_)) => {
let ty = module.arbitrary_super_type_of_val_type(u, ty)?;
instructions.push(Instruction::TypedSelect(ty));
Some(ty)
}
Some(ValType::I32) | Some(ValType::I64) | Some(ValType::F32) | Some(ValType::F64)
| Some(ValType::V128) | None => instructions.push(Instruction::Select),
}
| Some(ValType::V128) | None => {
instructions.push(Instruction::Select);
ty
}
};
builder.allocs.operands.push(ty);
Ok(())
}

Expand Down Expand Up @@ -5442,13 +5449,9 @@ fn ref_func(
) -> Result<()> {
let i = *u.choose(&builder.allocs.referenced_functions)?;
let ty = module.funcs[usize::try_from(i).unwrap()].0;
builder.push_operand(Some(ValType::Ref(if module.config.gc_enabled {
RefType {
nullable: false,
heap_type: HeapType::Concrete(ty),
}
} else {
RefType::FUNCREF
builder.push_operand(Some(ValType::Ref(RefType {
nullable: false,
heap_type: HeapType::Concrete(ty),
})));
instructions.push(Instruction::RefFunc(i));
Ok(())
Expand Down
Loading