Skip to content

Commit 3956462

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[wasm] add any.convert_extern, extern.convert_any
Very boring instructions but these instructions use the newly added subtyping of heap types, so an `extern.convert_any` can consume an indexed struct, indexed array, i31ref, or any other subtype of anyref including non-nullable types. Bug: 430171132 Change-Id: I948535446b6f340cf6ff2f55e6cb68cdfb6f3d2a Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8457859 Reviewed-by: Manos Koukoutos <[email protected]> Commit-Queue: Matthias Liedtke <[email protected]>
1 parent 672b969 commit 3956462

17 files changed

+240
-2
lines changed

Sources/Fuzzilli/Base/ProgramBuilder.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3776,6 +3776,16 @@ public class ProgramBuilder {
37763776
public func wasmI31Get(_ refI31: Variable, isSigned: Bool) -> Variable {
37773777
return b.emit(WasmI31Get(isSigned: isSigned), withInputs: [refI31], types: [.wasmI31Ref]).output
37783778
}
3779+
3780+
@discardableResult
3781+
public func wasmAnyConvertExtern(_ ref: Variable) -> Variable {
3782+
b.emit(WasmAnyConvertExtern(), withInputs: [ref], types: [.wasmExternRef]).output
3783+
}
3784+
3785+
@discardableResult
3786+
public func wasmExternConvertAny(_ ref: Variable) -> Variable {
3787+
b.emit(WasmExternConvertAny(), withInputs: [ref], types: [.wasmAnyRef]).output
3788+
}
37793789
}
37803790

37813791
public class WasmModule {

Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,6 @@ public let codeGeneratorWeights = [
337337
"WasmRefIsNullGenerator": 5,
338338
"WasmRefI31Generator": 5,
339339
"WasmI31GetGenerator": 5,
340+
"WasmAnyConvertExternGenerator": 5,
341+
"WasmExternConvertAnyGenerator": 5,
340342
]

Sources/Fuzzilli/CodeGen/WasmCodeGenerators.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ public let WasmCodeGenerators: [CodeGenerator] = [
248248
b.currentWasmModule.currentWasmFunction.wasmI31Get(ref, isSigned: Bool.random())
249249
},
250250

251+
CodeGenerator("WasmAnyConvertExternGenerator", inContext: .wasmFunction, inputs: .required(.wasmExternRef)) { b, ref in
252+
b.currentWasmModule.currentWasmFunction.wasmAnyConvertExtern(ref)
253+
},
254+
255+
CodeGenerator("WasmExternConvertAnyGenerator", inContext: .wasmFunction, inputs: .required(.wasmAnyRef)) { b, ref in
256+
b.currentWasmModule.currentWasmFunction.wasmExternConvertAny(ref)
257+
},
258+
251259
// Primitive Value Generators
252260

253261
ValueGenerator("WasmLoadi32Generator", inContext: .wasmFunction) { b, n in

Sources/Fuzzilli/FuzzIL/Instruction.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,10 @@ extension Instruction: ProtobufConvertible {
15511551
$0.wasmI31Get = Fuzzilli_Protobuf_WasmI31Get.with {
15521552
$0.isSigned = op.isSigned
15531553
}
1554+
case .wasmAnyConvertExtern(_):
1555+
$0.wasmAnyConvertExtern = Fuzzilli_Protobuf_WasmAnyConvertExtern()
1556+
case .wasmExternConvertAny(_):
1557+
$0.wasmExternConvertAny = Fuzzilli_Protobuf_WasmExternConvertAny()
15541558
}
15551559
}
15561560

@@ -2495,6 +2499,10 @@ extension Instruction: ProtobufConvertible {
24952499
op = WasmAtomicLoad(loadType: try convertEnum(p.loadType, WasmAtomicLoadType.allCases), offset: p.offset)
24962500
case .wasmAtomicStore(let p):
24972501
op = WasmAtomicStore(storeType: try convertEnum(p.storeType, WasmAtomicStoreType.allCases), offset: p.offset)
2502+
case .wasmAnyConvertExtern(_):
2503+
op = WasmAnyConvertExtern()
2504+
case .wasmExternConvertAny(_):
2505+
op = WasmExternConvertAny()
24982506
}
24992507

25002508
guard op.numInputs + op.numOutputs + op.numInnerOutputs == inouts.count else {

Sources/Fuzzilli/FuzzIL/JSTyper.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,14 @@ public struct JSTyper: Analyzer {
810810
setType(of: instr.output, to: .wasmRefI31)
811811
case .wasmI31Get(_):
812812
setType(of: instr.output, to: .wasmi32)
813+
case .wasmAnyConvertExtern(_):
814+
// any.convert_extern forwards the nullability bit from the input.
815+
let null = type(of: instr.input(0)).wasmReferenceType!.nullability
816+
setType(of: instr.output, to: .wasmRef(.Abstract(.WasmAny), nullability: null))
817+
case .wasmExternConvertAny(_):
818+
// extern.convert_any forwards the nullability bit from the input.
819+
let null = type(of: instr.input(0)).wasmReferenceType!.nullability
820+
setType(of: instr.output, to: .wasmRef(.Abstract(.WasmExtern), nullability: null))
813821
default:
814822
if instr.numInnerOutputs + instr.numOutputs != 0 {
815823
fatalError("Missing typing of outputs for \(instr.op.opcode)")

Sources/Fuzzilli/FuzzIL/Opcodes.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,6 @@ enum Opcode {
351351
case wasmRefIsNull(WasmRefIsNull)
352352
case wasmRefI31(WasmRefI31)
353353
case wasmI31Get(WasmI31Get)
354+
case wasmAnyConvertExtern(WasmAnyConvertExtern)
355+
case wasmExternConvertAny(WasmExternConvertAny)
354356
}

Sources/Fuzzilli/FuzzIL/TypeSystem.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,14 @@ public struct ILType: Hashable {
226226
public static let wasmf32 = ILType(definiteType: .wasmf32)
227227
public static let wasmf64 = ILType(definiteType: .wasmf64)
228228
public static let wasmExternRef = ILType.wasmRef(.Abstract(.WasmExtern), nullability: true)
229+
public static let wasmRefExtern = ILType.wasmRef(.Abstract(.WasmExtern), nullability: false)
229230
public static let wasmFuncRef = ILType.wasmRef(.Abstract(.WasmFunc), nullability: true)
230231
public static let wasmExnRef = ILType.wasmRef(.Abstract(.WasmExn), nullability: true)
231232
public static let wasmI31Ref = ILType.wasmRef(.Abstract(.WasmI31), nullability: true)
232233
public static let wasmAnyRef = ILType.wasmRef(.Abstract(.WasmAny), nullability: true)
234+
public static let wasmRefAny = ILType.wasmRef(.Abstract(.WasmAny), nullability: false)
235+
public static let wasmNullRef = ILType.wasmRef(.Abstract(.WasmNone), nullability: true)
236+
public static let wasmNullExternRef = ILType.wasmRef(.Abstract(.WasmNoExtern), nullability: true)
233237
public static let wasmEqRef = ILType.wasmRef(.Abstract(.WasmEq), nullability: true)
234238
public static let wasmStructRef = ILType.wasmRef(.Abstract(.WasmStruct), nullability: true)
235239
public static let wasmArrayRef = ILType.wasmRef(.Abstract(.WasmArray), nullability: true)

Sources/Fuzzilli/FuzzIL/WasmOperations.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,22 @@ class WasmI31Get: WasmOperation {
20952095
}
20962096
}
20972097

2098+
class WasmAnyConvertExtern: WasmOperation {
2099+
override var opcode: Opcode { .wasmAnyConvertExtern(self) }
2100+
2101+
init() {
2102+
super.init(numInputs: 1, numOutputs: 1, requiredContext: [.wasmFunction])
2103+
}
2104+
}
2105+
2106+
class WasmExternConvertAny: WasmOperation {
2107+
override var opcode: Opcode { .wasmExternConvertAny(self) }
2108+
2109+
init() {
2110+
super.init(numInputs: 1, numOutputs: 1, requiredContext: [.wasmFunction])
2111+
}
2112+
}
2113+
20982114
/// An atomic load from Wasm memory.
20992115
/// The accessed address is base + offset.
21002116
final class WasmAtomicLoad: WasmOperation {

Sources/Fuzzilli/Lifting/FuzzILLifter.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,12 @@ public class FuzzILLifter: Lifter {
12691269
case .wasmI31Get(let op):
12701270
w.emit("\(output()) <- WasmI31Get \(op.isSigned ? "signed" : "unsigned") \(input(0))")
12711271

1272+
case .wasmAnyConvertExtern(_):
1273+
w.emit("\(output()) <- WasmAnyConvertExtern \(input(0))")
1274+
1275+
case .wasmExternConvertAny(_):
1276+
w.emit("\(output()) <- WasmExternConvertAny \(input(0))")
1277+
12721278
case .wasmBeginTypeGroup(_):
12731279
w.emit("WasmBeginTypeGroup")
12741280
w.increaseIndentionLevel()

Sources/Fuzzilli/Lifting/JavaScriptLifter.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,9 @@ public class JavaScriptLifter: Lifter {
16981698
.wasmRefNull(_),
16991699
.wasmRefIsNull(_),
17001700
.wasmRefI31(_),
1701-
.wasmI31Get(_):
1701+
.wasmI31Get(_),
1702+
.wasmAnyConvertExtern(_),
1703+
.wasmExternConvertAny(_):
17021704
fatalError("unreachable")
17031705
}
17041706

0 commit comments

Comments
 (0)