Skip to content

Commit 66f0b84

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

6 files changed

Lines changed: 13 additions & 30 deletions

File tree

Sources/Fuzzilli/Base/ProgramBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3954,7 +3954,7 @@ public class ProgramBuilder {
39543954
public func wasmBranch(to label: Variable, args: [Variable] = []) {
39553955
let labelType = b.type(of: label)
39563956
checkArgumentsMatchLabelType(label: labelType, args: args)
3957-
b.emit(WasmBranch(labelTypes: labelType.wasmLabelType!.parameters), withInputs: [label] + args)
3957+
b.emit(WasmBranch(parameterCount: labelType.wasmLabelType!.parameters.count), withInputs: [label] + args)
39583958
}
39593959

39603960
public func wasmBranchIf(_ condition: Variable, to label: Variable, args: [Variable] = [], hint: WasmBranchHint = .None) {

Sources/Fuzzilli/FuzzIL/Instruction.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,10 +1447,8 @@ extension Instruction: ProtobufConvertible {
14471447
$0.wasmDefineTag = Fuzzilli_Protobuf_WasmDefineTag.with {
14481448
$0.parameterTypes = op.parameterTypes.map(ILTypeToWasmTypeEnum)
14491449
}
1450-
case .wasmBranch(let op):
1451-
$0.wasmBranch = Fuzzilli_Protobuf_WasmBranch.with {
1452-
$0.parameters = op.labelTypes.map(ILTypeToWasmTypeEnum)
1453-
}
1450+
case .wasmBranch(_):
1451+
$0.wasmBranch = Fuzzilli_Protobuf_WasmBranch()
14541452
case .wasmBranchIf(let op):
14551453
$0.wasmBranchIf = Fuzzilli_Protobuf_WasmBranchIf.with {
14561454
$0.parameters = op.labelTypes.map(ILTypeToWasmTypeEnum)
@@ -2494,8 +2492,8 @@ extension Instruction: ProtobufConvertible {
24942492
op = WasmRethrow()
24952493
case .wasmDefineTag(let p):
24962494
op = WasmDefineTag(parameterTypes: p.parameterTypes.map(WasmTypeEnumToILType))
2497-
case .wasmBranch(let p):
2498-
op = WasmBranch(labelTypes: p.parameters.map(WasmTypeEnumToILType))
2495+
case .wasmBranch(_):
2496+
op = WasmBranch(parameterCount: inouts.count - 1)
24992497
case .wasmBranchIf(let p):
25002498
op = WasmBranchIf(labelTypes: p.parameters.map(WasmTypeEnumToILType), hint: try convertEnum(p.hint, WasmBranchHint.allCases))
25012499
case .wasmBranchTable(let p):

Sources/Fuzzilli/FuzzIL/WasmOperations.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,13 +1494,12 @@ final class WasmRethrow: WasmOperation {
14941494

14951495
final class WasmBranch: WasmOperation {
14961496
override var opcode: Opcode { .wasmBranch(self) }
1497-
let labelTypes: [ILType]
1498-
1499-
init(labelTypes: [ILType]) {
1500-
self.labelTypes = labelTypes
1501-
super.init(numInputs: 1 + labelTypes.count, requiredContext: [.wasmFunction])
15021497

1498+
init(parameterCount: Int) {
1499+
super.init(numInputs: 1 + parameterCount, requiredContext: [.wasmFunction])
15031500
}
1501+
1502+
var parameterCount: Int {numInputs - 1}
15041503
}
15051504

15061505
final class WasmBranchIf: WasmOperation {

Sources/Fuzzilli/Lifting/WasmLifter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ public class WasmLifter {
19571957
return Data([0x09] + Leb128.unsignedEncode(blockDepth))
19581958
case .wasmBranch(let op):
19591959
let branchDepth = try branchDepthFor(label: wasmInstruction.input(0))
1960-
return Data([0x0C]) + Leb128.unsignedEncode(branchDepth) + Data(op.labelTypes.map {_ in 0x1A})
1960+
return Data([0x0C]) + Leb128.unsignedEncode(branchDepth) + Array(repeating: 0x1a, count: op.parameterCount)
19611961
case .wasmBranchIf(let op):
19621962
currentFunction!.addBranchHint(op.hint)
19631963
let branchDepth = try branchDepthFor(label: wasmInstruction.input(0))

Sources/Fuzzilli/Protobuf/operations.pb.swift

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5343,8 +5343,6 @@ public struct Fuzzilli_Protobuf_WasmBranch: Sendable {
53435343
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
53445344
// methods supported on all messages.
53455345

5346-
public var parameters: [Fuzzilli_Protobuf_WasmILType] = []
5347-
53485346
public var unknownFields = SwiftProtobuf.UnknownStorage()
53495347

53505348
public init() {}
@@ -14139,29 +14137,18 @@ extension Fuzzilli_Protobuf_WasmDefineTag: SwiftProtobuf.Message, SwiftProtobuf.
1413914137

1414014138
extension Fuzzilli_Protobuf_WasmBranch: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
1414114139
public static let protoMessageName: String = _protobuf_package + ".WasmBranch"
14142-
public static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{1}parameters\0")
14140+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()
1414314141

1414414142
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
14145-
while let fieldNumber = try decoder.nextFieldNumber() {
14146-
// The use of inline closures is to circumvent an issue where the compiler
14147-
// allocates stack space for every case branch when no optimizations are
14148-
// enabled. https://github.com/apple/swift-protobuf/issues/1034
14149-
switch fieldNumber {
14150-
case 1: try { try decoder.decodeRepeatedMessageField(value: &self.parameters) }()
14151-
default: break
14152-
}
14153-
}
14143+
// Load everything into unknown fields
14144+
while try decoder.nextFieldNumber() != nil {}
1415414145
}
1415514146

1415614147
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
14157-
if !self.parameters.isEmpty {
14158-
try visitor.visitRepeatedMessageField(value: self.parameters, fieldNumber: 1)
14159-
}
1416014148
try unknownFields.traverse(visitor: &visitor)
1416114149
}
1416214150

1416314151
public static func ==(lhs: Fuzzilli_Protobuf_WasmBranch, rhs: Fuzzilli_Protobuf_WasmBranch) -> Bool {
14164-
if lhs.parameters != rhs.parameters {return false}
1416514152
if lhs.unknownFields != rhs.unknownFields {return false}
1416614153
return true
1416714154
}

Sources/Fuzzilli/Protobuf/operations.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,6 @@ message WasmDefineTag {
13111311
}
13121312

13131313
message WasmBranch {
1314-
repeated WasmILType parameters = 1;
13151314
}
13161315

13171316
enum WasmBranchHint {

0 commit comments

Comments
 (0)