Skip to content

Commit 38b76d7

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[wasm] Allow reference types in parameters and results of wasm functions
Bug: 430198271 Change-Id: I4e1976237e632527c922188b9dbb6140e705a21c Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8460621 Reviewed-by: Manos Koukoutos <[email protected]> Auto-Submit: Matthias Liedtke <[email protected]> Commit-Queue: Manos Koukoutos <[email protected]>
1 parent 3956462 commit 38b76d7

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

Sources/Fuzzilli/Base/ProgramBuilder.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,14 +1111,14 @@ public class ProgramBuilder {
11111111
} else if type.Is(.wasmFuncRef) {
11121112
// TODO(cffsmith): refine this type with the signature if we can.
11131113
return .function()
1114-
} else if type.Is(.wasmExternRef) {
1115-
return .jsAnything
1116-
} else if type.Is(.wasmExnRef) {
1117-
return .jsAnything
1118-
} else if type.Is(.wasmGenericRef) {
1119-
return .jsAnything
11201114
} else if type.Is(.wasmI31Ref) {
11211115
return .integer
1116+
} else if type.Is(.wasmNullRef) || type.Is(.wasmNullExternRef) || type.Is(.wasmNullFuncRef) {
1117+
// This is slightly imprecise: The null types only accept null, not undefined but
1118+
// Fuzzilli doesn't differentiate between null and undefined in its type system.
1119+
return .nullish
1120+
} else if type.Is(.wasmGenericRef) {
1121+
return .jsAnything
11221122
} else {
11231123
fatalError("Unexpected type encountered: \(type).")
11241124
}
@@ -3950,9 +3950,17 @@ public class ProgramBuilder {
39503950
}
39513951

39523952
public func randomWasmSignature() -> WasmSignature {
3953-
// TODO: generalize this to support more types.
3954-
let returnTypes: [ILType] = (0..<Int.random(in: 0...3)).map {_ in chooseUniform(from: [.wasmi32, .wasmi64, .wasmf32, .wasmf64])}
3955-
let params: [ILType] = (0..<Int.random(in: 0...10)).map {_ in chooseUniform(from: [.wasmi32, .wasmf32, .wasmf64])}
3953+
// TODO: generalize this to support more types. Also add support for simd128 and
3954+
// (null)exnref, note however that these types raise exceptions when used from JS.
3955+
let valueTypes: [ILType] = [.wasmi32, .wasmi64, .wasmf32, .wasmf64]
3956+
let abstractRefTypes: [ILType] = [.wasmExternRef, .wasmAnyRef, .wasmI31Ref]
3957+
let nullTypes: [ILType] = [.wasmNullRef, .wasmNullExternRef, .wasmNullFuncRef]
3958+
let randomType = {
3959+
chooseUniform(
3960+
from: chooseBiased(from: [nullTypes, abstractRefTypes, valueTypes], factor: 1.5))
3961+
}
3962+
let returnTypes: [ILType] = (0..<Int.random(in: 0...3)).map {_ in randomType()}
3963+
let params: [ILType] = (0..<Int.random(in: 0...10)).map {_ in randomType()}
39563964
return params => returnTypes
39573965
}
39583966

Sources/Fuzzilli/FuzzIL/TypeSystem.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public struct ILType: Hashable {
234234
public static let wasmRefAny = ILType.wasmRef(.Abstract(.WasmAny), nullability: false)
235235
public static let wasmNullRef = ILType.wasmRef(.Abstract(.WasmNone), nullability: true)
236236
public static let wasmNullExternRef = ILType.wasmRef(.Abstract(.WasmNoExtern), nullability: true)
237+
public static let wasmNullFuncRef = ILType.wasmRef(.Abstract(.WasmNoFunc), nullability: true)
237238
public static let wasmEqRef = ILType.wasmRef(.Abstract(.WasmEq), nullability: true)
238239
public static let wasmStructRef = ILType.wasmRef(.Abstract(.WasmStruct), nullability: true)
239240
public static let wasmArrayRef = ILType.wasmRef(.Abstract(.WasmArray), nullability: true)

Tests/FuzzilliTests/LiveTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ class LiveTests: XCTestCase {
117117
return b.loadBigInt(123)
118118
case .wasmFuncRef:
119119
return jsFunction
120+
case .wasmNullExternRef, .wasmNullFuncRef, .wasmNullRef:
121+
return b.loadNull()
122+
case .wasmExternRef, .wasmAnyRef:
123+
return b.createObject(with: [:])
120124
default:
121125
return b.loadInt(321)
122126
}

0 commit comments

Comments
 (0)