Skip to content

Commit 9cc25ac

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

7 files changed

Lines changed: 11 additions & 18 deletions

File tree

Sources/Fuzzilli/Base/ProgramBuilder.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3961,7 +3961,9 @@ public class ProgramBuilder {
39613961
let labelType = b.type(of: label)
39623962
checkArgumentsMatchLabelType(label: labelType, args: args)
39633963
assert(b.type(of: condition).Is(.wasmi32))
3964-
b.emit(WasmBranchIf(labelTypes: labelType.wasmLabelType!.parameters, hint: hint), withInputs: [label] + args + [condition])
3964+
b.emit(
3965+
WasmBranchIf(parameterCount: labelType.wasmLabelType!.parameters.count, hint: hint),
3966+
withInputs: [label] + args + [condition])
39653967
}
39663968

39673969
public func wasmBranchTable(on: Variable, labels: [Variable], args: [Variable]) {

Sources/Fuzzilli/FuzzIL/Instruction.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,6 @@ extension Instruction: ProtobufConvertible {
14511451
$0.wasmBranch = Fuzzilli_Protobuf_WasmBranch()
14521452
case .wasmBranchIf(let op):
14531453
$0.wasmBranchIf = Fuzzilli_Protobuf_WasmBranchIf.with {
1454-
$0.parameters = op.labelTypes.map(ILTypeToWasmTypeEnum)
14551454
$0.hint = convertEnum(op.hint, WasmBranchHint.allCases)
14561455
}
14571456
case .wasmBranchTable(let op):
@@ -2495,7 +2494,7 @@ extension Instruction: ProtobufConvertible {
24952494
case .wasmBranch(_):
24962495
op = WasmBranch(parameterCount: inouts.count - 1)
24972496
case .wasmBranchIf(let p):
2498-
op = WasmBranchIf(labelTypes: p.parameters.map(WasmTypeEnumToILType), hint: try convertEnum(p.hint, WasmBranchHint.allCases))
2497+
op = WasmBranchIf(parameterCount: inouts.count - 2, hint: try convertEnum(p.hint, WasmBranchHint.allCases))
24992498
case .wasmBranchTable(let p):
25002499
op = WasmBranchTable(labelTypes: p.parameters.map(WasmTypeEnumToILType), valueCount: Int(p.valueCount))
25012500
case .wasmBeginIf(let p):

Sources/Fuzzilli/FuzzIL/WasmOperations.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,15 +1504,15 @@ final class WasmBranch: WasmOperation {
15041504

15051505
final class WasmBranchIf: WasmOperation {
15061506
override var opcode: Opcode { .wasmBranchIf(self) }
1507-
let labelTypes: [ILType]
15081507
let hint: WasmBranchHint
15091508

1510-
init(labelTypes: [ILType], hint: WasmBranchHint) {
1511-
self.labelTypes = labelTypes
1509+
init(parameterCount: Int, hint: WasmBranchHint) {
15121510
self.hint = hint
15131511
// The inputs are the label, the arguments and the condition.
1514-
super.init(numInputs: 1 + labelTypes.count + 1, attributes: [.isMutable], requiredContext: [.wasmFunction])
1512+
super.init(numInputs: 1 + parameterCount + 1, attributes: [.isMutable], requiredContext: [.wasmFunction])
15151513
}
1514+
1515+
var parameterCount: Int {numInputs - 2}
15161516
}
15171517

15181518
final class WasmBranchTable: WasmOperation {

Sources/Fuzzilli/Lifting/WasmLifter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ public class WasmLifter {
19611961
case .wasmBranchIf(let op):
19621962
currentFunction!.addBranchHint(op.hint)
19631963
let branchDepth = try branchDepthFor(label: wasmInstruction.input(0))
1964-
return Data([0x0D]) + Leb128.unsignedEncode(branchDepth) + Data(op.labelTypes.map {_ in 0x1A})
1964+
return Data([0x0D]) + Leb128.unsignedEncode(branchDepth) + Array(repeating: 0x1a, count: op.parameterCount)
19651965
case .wasmBranchTable(let op):
19661966
let depths = try (0...op.valueCount).map {
19671967
try branchDepthFor(label: wasmInstruction.input($0))

Sources/Fuzzilli/Mutators/OperationMutator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ public class OperationMutator: BaseInstructionMutator {
497497
: Int64.random(in: Int64.min...Int64.max) // most likely out of bounds
498498
newOp = WasmSimdLoad(kind: kind, staticOffset: staticOffset)
499499
case .wasmBranchIf(let op):
500-
newOp = WasmBranchIf(labelTypes: op.labelTypes, hint: chooseUniform(from: WasmBranchHint.allCases))
500+
newOp = WasmBranchIf(parameterCount: op.parameterCount, hint: chooseUniform(from: WasmBranchHint.allCases))
501501
case .wasmBeginIf(let op):
502502
newOp = WasmBeginIf(parameterCount: op.parameterCount, hint: chooseUniform(from: WasmBranchHint.allCases), inverted: Bool.random())
503503
case .wasmArrayGet(let op):

Sources/Fuzzilli/Protobuf/operations.pb.swift

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

5356-
public var parameters: [Fuzzilli_Protobuf_WasmILType] = []
5357-
53585356
public var hint: Fuzzilli_Protobuf_WasmBranchHint = .branchhintNone
53595357

53605358
public var unknownFields = SwiftProtobuf.UnknownStorage()
@@ -14156,33 +14154,28 @@ extension Fuzzilli_Protobuf_WasmBranch: SwiftProtobuf.Message, SwiftProtobuf._Me
1415614154

1415714155
extension Fuzzilli_Protobuf_WasmBranchIf: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
1415814156
public static let protoMessageName: String = _protobuf_package + ".WasmBranchIf"
14159-
public static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{1}parameters\0\u{1}hint\0")
14157+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{2}\u{2}hint\0")
1416014158

1416114159
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
1416214160
while let fieldNumber = try decoder.nextFieldNumber() {
1416314161
// The use of inline closures is to circumvent an issue where the compiler
1416414162
// allocates stack space for every case branch when no optimizations are
1416514163
// enabled. https://github.com/apple/swift-protobuf/issues/1034
1416614164
switch fieldNumber {
14167-
case 1: try { try decoder.decodeRepeatedMessageField(value: &self.parameters) }()
1416814165
case 2: try { try decoder.decodeSingularEnumField(value: &self.hint) }()
1416914166
default: break
1417014167
}
1417114168
}
1417214169
}
1417314170

1417414171
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
14175-
if !self.parameters.isEmpty {
14176-
try visitor.visitRepeatedMessageField(value: self.parameters, fieldNumber: 1)
14177-
}
1417814172
if self.hint != .branchhintNone {
1417914173
try visitor.visitSingularEnumField(value: self.hint, fieldNumber: 2)
1418014174
}
1418114175
try unknownFields.traverse(visitor: &visitor)
1418214176
}
1418314177

1418414178
public static func ==(lhs: Fuzzilli_Protobuf_WasmBranchIf, rhs: Fuzzilli_Protobuf_WasmBranchIf) -> Bool {
14185-
if lhs.parameters != rhs.parameters {return false}
1418614179
if lhs.hint != rhs.hint {return false}
1418714180
if lhs.unknownFields != rhs.unknownFields {return false}
1418814181
return true

Sources/Fuzzilli/Protobuf/operations.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,6 @@ enum WasmBranchHint {
13201320
}
13211321

13221322
message WasmBranchIf {
1323-
repeated WasmILType parameters = 1;
13241323
WasmBranchHint hint = 2;
13251324
}
13261325

0 commit comments

Comments
 (0)