Skip to content

Commit

Permalink
Propagate shared function type into the code builder
Browse files Browse the repository at this point in the history
  • Loading branch information
abrown committed Oct 18, 2024
1 parent 94f5d48 commit 5947f92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crates/wasm-smith/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2258,8 +2258,9 @@ impl Module {

self.code.reserve(self.num_defined_funcs);
let mut allocs = CodeBuilderAllocations::new(self, self.config.exports.is_some());
for (_, ty) in self.funcs[self.funcs.len() - self.num_defined_funcs..].iter() {
let body = self.arbitrary_func_body(u, ty, &mut allocs)?;
for (idx, ty) in self.funcs[self.funcs.len() - self.num_defined_funcs..].iter() {
let shared = self.is_shared_type(*idx);
let body = self.arbitrary_func_body(u, ty, &mut allocs, shared)?;
self.code.push(body);
}
allocs.finish(u, self)?;
Expand All @@ -2271,9 +2272,10 @@ impl Module {
u: &mut Unstructured,
ty: &FuncType,
allocs: &mut CodeBuilderAllocations,
shared: bool,
) -> Result<Code> {
let mut locals = self.arbitrary_locals(u)?;
let builder = allocs.builder(ty, &mut locals);
let builder = allocs.builder(ty, &mut locals, shared);
let instructions = if self.config.allow_invalid_funcs && u.arbitrary().unwrap_or(false) {
Instructions::Arbitrary(arbitrary_vec_u8(u)?)
} else {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasm-smith/src/core/code_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ pub(crate) struct CodeBuilderAllocations {
}

pub(crate) struct CodeBuilder<'a> {
shared: bool,
func_ty: &'a FuncType,
locals: &'a mut Vec<ValType>,
allocs: &'a mut CodeBuilderAllocations,
Expand Down Expand Up @@ -903,6 +904,7 @@ impl CodeBuilderAllocations {
&'a mut self,
func_ty: &'a FuncType,
locals: &'a mut Vec<ValType>,
shared: bool,
) -> CodeBuilder<'a> {
self.controls.clear();
self.controls.push(Control {
Expand All @@ -916,6 +918,7 @@ impl CodeBuilderAllocations {
self.options.clear();

CodeBuilder {
shared,
func_ty,
locals,
allocs: self,
Expand Down

0 comments on commit 5947f92

Please sign in to comment.