Skip to content

Commit a923d15

Browse files
evicyV8-internal LUCI CQ
authored andcommitted
[improve livetests] Truncate integral floats to integers
The WasmTruncate[f32 | f64]To[i32 | i64]Generator-s got Wasm floats as inputs. Any non-integral float cannot be converted and the Wasm function will trap. After this change we generate integral floats to be truncated. This was a reason for LiveTests.testWasmCodeGenerationAndCompilationAndExecution failing in ~30% of the runs. Change-Id: Ib543c4366b99109eade453b2d9a106387a51bf00 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/7960389 Reviewed-by: Carl Smith <[email protected]> Commit-Queue: Eva Herencsárová <[email protected]>
1 parent fd3533d commit a923d15

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

Sources/Fuzzilli/CodeGen/WasmCodeGenerators.swift

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -373,25 +373,25 @@ public let WasmCodeGenerators: [CodeGenerator] = [
373373
function.wrapi64Toi32(input)
374374
},
375375

376-
CodeGenerator("WasmTruncatef32Toi32Generator", inContext: .wasmFunction, inputs: .required(.wasmf32)) { b, input in
377-
// We are using a trick here and for all other unsigned truncations. If the input is a negative float, the operation will result in a runtime error, therefore we will always emit an f32UnOp Abs() operation to make sure that the operation wont throw.
378-
// Minimization will then automatically remove the f32UnOp instruction if it is not necessary.
376+
CodeGenerator("WasmTruncatef32Toi32Generator", inContext: .wasmFunction) { b in
379377
let function = b.currentWasmModule.currentWasmFunction
380378
if probability(0.5) {
381-
let res = function.wasmf32UnOp(input, unOpKind: .Abs)
382-
function.truncatef32Toi32(res, isSigned: false)
379+
let value = function.constf32(Float32(b.randomSize(upTo: Int64(Int32.max))))
380+
function.truncatef32Toi32(value, isSigned: false)
383381
} else {
384-
function.truncatef32Toi32(input, isSigned: true)
382+
let value = function.constf32(Float32(b.randomInt() % Int64(Int32.max)))
383+
function.truncatef32Toi32(value, isSigned: true)
385384
}
386385
},
387386

388-
CodeGenerator("WasmTruncatef64Toi32Generator", inContext: .wasmFunction, inputs: .required(.wasmf64)) { b, input in
387+
CodeGenerator("WasmTruncatef64Toi32Generator", inContext: .wasmFunction) { b in
389388
let function = b.currentWasmModule.currentWasmFunction
390389
if probability(0.5) {
391-
let res = function.wasmf64UnOp(input, unOpKind: .Abs)
392-
function.truncatef64Toi32(res, isSigned: false)
390+
let value = function.constf64(Float64(b.randomSize(upTo: Int64(Int32.max))))
391+
function.truncatef64Toi32(value, isSigned: false)
393392
} else {
394-
function.truncatef64Toi32(input, isSigned: true)
393+
let value = function.constf64(Float64(b.randomInt() % Int64(Int32.max)))
394+
function.truncatef64Toi32(value, isSigned: true)
395395
}
396396
},
397397

@@ -410,13 +410,14 @@ public let WasmCodeGenerators: [CodeGenerator] = [
410410
}
411411
},
412412

413-
CodeGenerator("WasmTruncatef64Toi64Generator", inContext: .wasmFunction, inputs: .required(.wasmf64)) { b, input in
413+
CodeGenerator("WasmTruncatef64Toi64Generator", inContext: .wasmFunction) { b in
414414
let function = b.currentWasmModule.currentWasmFunction
415415
if probability(0.5) {
416-
let res = function.wasmf64UnOp(input, unOpKind: .Abs)
417-
function.truncatef64Toi64(res, isSigned: false)
416+
let value = function.constf64(Float64(b.randomSize()))
417+
function.truncatef64Toi64(value, isSigned: false)
418418
} else {
419-
function.truncatef64Toi64(input, isSigned: true)
419+
let value = function.constf64(Float64(b.randomInt()))
420+
function.truncatef64Toi64(value, isSigned: true)
420421
}
421422
},
422423

0 commit comments

Comments
 (0)