Skip to content

Commit d53f176

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[wasm] Remove parameter types from wasmBranchTable
Bug: 445356784 Change-Id: Ia1a6b4606ba85e5c6f0093cc8c43cc4726a7b907 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8926699 Reviewed-by: Doga Yüksel <dyuksel@google.com> Commit-Queue: Matthias Liedtke <mliedtke@google.com>
1 parent 9cc25ac commit d53f176

5 files changed

Lines changed: 9 additions & 20 deletions

File tree

Sources/Fuzzilli/Base/ProgramBuilder.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3967,11 +3967,8 @@ public class ProgramBuilder {
39673967
}
39683968

39693969
public func wasmBranchTable(on: Variable, labels: [Variable], args: [Variable]) {
3970-
let argumentTypes = args.map({b.type(of: $0)})
3971-
labels.forEach {
3972-
checkArgumentsMatchLabelType(label: b.type(of: $0), args: args)
3973-
}
3974-
b.emit(WasmBranchTable(labelTypes: argumentTypes, valueCount: labels.count - 1),
3970+
labels.forEach { checkArgumentsMatchLabelType(label: b.type(of: $0), args: args) }
3971+
b.emit(WasmBranchTable(parameterCount: args.count, valueCount: labels.count - 1),
39753972
withInputs: labels + args + [on])
39763973
}
39773974

Sources/Fuzzilli/FuzzIL/Instruction.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,6 @@ extension Instruction: ProtobufConvertible {
14551455
}
14561456
case .wasmBranchTable(let op):
14571457
$0.wasmBranchTable = Fuzzilli_Protobuf_WasmBranchTable.with {
1458-
$0.parameters = op.labelTypes.map(ILTypeToWasmTypeEnum)
14591458
$0.valueCount = UInt32(op.valueCount)
14601459
}
14611460
case .wasmBeginIf(let op):
@@ -2496,7 +2495,7 @@ extension Instruction: ProtobufConvertible {
24962495
case .wasmBranchIf(let p):
24972496
op = WasmBranchIf(parameterCount: inouts.count - 2, hint: try convertEnum(p.hint, WasmBranchHint.allCases))
24982497
case .wasmBranchTable(let p):
2499-
op = WasmBranchTable(labelTypes: p.parameters.map(WasmTypeEnumToILType), valueCount: Int(p.valueCount))
2498+
op = WasmBranchTable(parameterCount: inouts.count - Int(p.valueCount) - 2, valueCount: Int(p.valueCount))
25002499
case .wasmBeginIf(let p):
25012500
op = WasmBeginIf(parameterCount: Int(p.parameterCount), hint: try convertEnum(p.hint, WasmBranchHint.allCases), inverted: p.inverted)
25022501
case .wasmBeginElse(let p):

Sources/Fuzzilli/FuzzIL/WasmOperations.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,16 +1517,17 @@ final class WasmBranchIf: WasmOperation {
15171517

15181518
final class WasmBranchTable: WasmOperation {
15191519
override var opcode: Opcode { .wasmBranchTable(self) }
1520-
let labelTypes: [ILType]
15211520
// The number of cases in the br_table. Note that the number of labels is one higher as each
15221521
// br_table has a default label.
15231522
let valueCount: Int
15241523

1525-
init(labelTypes: [ILType], valueCount: Int) {
1526-
self.labelTypes = labelTypes
1524+
init(parameterCount: Int, valueCount: Int) {
15271525
self.valueCount = valueCount
1528-
super.init(numInputs: valueCount + 1 + labelTypes.count + 1, requiredContext: [.wasmFunction])
1526+
// Inputs: the case labels, the default label, the arguments and the condition.
1527+
super.init(numInputs: valueCount + 1 + parameterCount + 1, requiredContext: [.wasmFunction])
15291528
}
1529+
1530+
var parameterCount: Int {numInputs - valueCount - 2}
15301531
}
15311532

15321533
// TODO: make this comprehensive, currently only works for locals, or assumes every thing it reassigns to is a local.

Sources/Fuzzilli/Protobuf/operations.pb.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5365,8 +5365,6 @@ public struct Fuzzilli_Protobuf_WasmBranchTable: Sendable {
53655365
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
53665366
// methods supported on all messages.
53675367

5368-
public var parameters: [Fuzzilli_Protobuf_WasmILType] = []
5369-
53705368
public var valueCount: UInt32 = 0
53715369

53725370
public var unknownFields = SwiftProtobuf.UnknownStorage()
@@ -14184,33 +14182,28 @@ extension Fuzzilli_Protobuf_WasmBranchIf: SwiftProtobuf.Message, SwiftProtobuf._
1418414182

1418514183
extension Fuzzilli_Protobuf_WasmBranchTable: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
1418614184
public static let protoMessageName: String = _protobuf_package + ".WasmBranchTable"
14187-
public static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{1}parameters\0\u{1}valueCount\0")
14185+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{2}\u{2}valueCount\0")
1418814186

1418914187
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
1419014188
while let fieldNumber = try decoder.nextFieldNumber() {
1419114189
// The use of inline closures is to circumvent an issue where the compiler
1419214190
// allocates stack space for every case branch when no optimizations are
1419314191
// enabled. https://github.com/apple/swift-protobuf/issues/1034
1419414192
switch fieldNumber {
14195-
case 1: try { try decoder.decodeRepeatedMessageField(value: &self.parameters) }()
1419614193
case 2: try { try decoder.decodeSingularUInt32Field(value: &self.valueCount) }()
1419714194
default: break
1419814195
}
1419914196
}
1420014197
}
1420114198

1420214199
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
14203-
if !self.parameters.isEmpty {
14204-
try visitor.visitRepeatedMessageField(value: self.parameters, fieldNumber: 1)
14205-
}
1420614200
if self.valueCount != 0 {
1420714201
try visitor.visitSingularUInt32Field(value: self.valueCount, fieldNumber: 2)
1420814202
}
1420914203
try unknownFields.traverse(visitor: &visitor)
1421014204
}
1421114205

1421214206
public static func ==(lhs: Fuzzilli_Protobuf_WasmBranchTable, rhs: Fuzzilli_Protobuf_WasmBranchTable) -> Bool {
14213-
if lhs.parameters != rhs.parameters {return false}
1421414207
if lhs.valueCount != rhs.valueCount {return false}
1421514208
if lhs.unknownFields != rhs.unknownFields {return false}
1421614209
return true

Sources/Fuzzilli/Protobuf/operations.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,6 @@ message WasmBranchIf {
13241324
}
13251325

13261326
message WasmBranchTable {
1327-
repeated WasmILType parameters = 1;
13281327
uint32 valueCount = 2;
13291328
}
13301329

0 commit comments

Comments
 (0)