Skip to content
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
9 changes: 9 additions & 0 deletions Sources/Fuzzilli/Base/ProgramBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2711,4 +2711,13 @@ public class ProgramBuilder {
break
}
}

public func buildIteratorVariable(_ b: ProgramBuilder, _ it: Variable) -> Variable{
if(b.type(of: it).Is(.iterable)){
return it
}
let initialValues = (0..<Int.random(in: 1...5)).map({ _ in b.randomVariable() })
return b.createArray(with: initialValues)
}

}
10 changes: 5 additions & 5 deletions Sources/Fuzzilli/CodeGen/CodeGenerators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -769,13 +769,13 @@ public let CodeGenerators: [CodeGenerator] = [
// These are "typically" used as arguments, so we don't directly generate a call operation here.
},

RecursiveCodeGenerator("GeneratorFunctionGenerator") { b in
RecursiveCodeGenerator("GeneratorFunctionGenerator", inputs: .preferred(.iterable)) { b, it in
let f = b.buildGeneratorFunction(with: b.randomParameters(), isStrict: probability(0.1)) { _ in
b.buildRecursive()
if probability(0.5) {
b.yield(b.randomVariable())
} else {
b.yieldEach(b.randomVariable())
b.yieldEach(b.buildIteratorVariable(b, it))
}
b.doReturn(b.randomVariable())
}
Expand All @@ -800,14 +800,14 @@ public let CodeGenerators: [CodeGenerator] = [
// These are "typically" used as arguments, so we don't directly generate a call operation here.
},

RecursiveCodeGenerator("AsyncGeneratorFunctionGenerator") { b in
RecursiveCodeGenerator("AsyncGeneratorFunctionGenerator", inputs: .preferred(.iterable)) { b, it in
let f = b.buildAsyncGeneratorFunction(with: b.randomParameters(), isStrict: probability(0.1)) { _ in
b.buildRecursive()
b.await(b.randomVariable())
if probability(0.5) {
b.yield(b.randomVariable())
} else {
b.yieldEach(b.randomVariable())
b.yieldEach(b.buildIteratorVariable(b, it))
}
b.doReturn(b.randomVariable())
}
Expand Down Expand Up @@ -1085,7 +1085,7 @@ public let CodeGenerators: [CodeGenerator] = [
}
} else {
// TODO only do this when the value is iterable?
b.yieldEach(val)
b.yieldEach(b.buildIteratorVariable(b, val))
}
},

Expand Down