Commit 17a88670 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Allow traps in tests with many parameters in cctests

In the test-run-wasm and test-run-wasm-64 cctests it is not possible to
call runtime functions. To test traps in these cctests we therefore
replace the runtime call with a call to a c-callback, followed by a
return. This CL fixes the problem that the return did not clean up stack
parameters.

This CL unblocks
https://chromium-review.googlesource.com/c/v8/v8/+/671008. Originally I
wanted to mitigate the problem in that CL by defining an additional
parameter register for arm. However, adding additional parameter
registers lets other tests fail.

R=titzer@chromium.org, rodolph.perfetta@arm.com
CC=enricobacis@google.com

Bug: v8:6858
Change-Id: Ia8de73b70a0677ca4d379ed5b16272faee92a78d
Reviewed-on: https://chromium-review.googlesource.com/684017Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48158}
parent 34ac2b7b
......@@ -2691,6 +2691,9 @@ void CodeGenerator::AssembleArchTrap(Instruction* instr,
__ isolate()),
0);
__ LeaveFrame(StackFrame::WASM_COMPILED);
CallDescriptor* descriptor = gen_->linkage()->GetIncomingDescriptor();
int pop_count = static_cast<int>(descriptor->StackParameterCount());
__ Drop(pop_count);
__ Ret();
} else {
gen_->AssembleSourcePosition(instr_);
......
......@@ -2363,6 +2363,10 @@ void CodeGenerator::AssembleArchTrap(Instruction* instr,
__ isolate()),
0);
__ LeaveFrame(StackFrame::WASM_COMPILED);
CallDescriptor* descriptor = gen_->linkage()->GetIncomingDescriptor();
int pop_count = static_cast<int>(descriptor->StackParameterCount());
pop_count += (pop_count & 1); // align
__ Drop(pop_count);
__ Ret();
} else {
DCHECK(csp.Is(__ StackPointer()));
......
......@@ -2498,7 +2498,10 @@ void CodeGenerator::AssembleArchTrap(Instruction* instr,
__ isolate()),
0);
__ LeaveFrame(StackFrame::WASM_COMPILED);
__ Ret();
CallDescriptor* descriptor = gen_->linkage()->GetIncomingDescriptor();
size_t pop_size = descriptor->StackParameterCount() * kPointerSize;
// Use ecx as a scratch register, we return anyways immediately.
__ Ret(static_cast<int>(pop_size), ecx);
} else {
gen_->AssembleSourcePosition(instr_);
__ Call(__ isolate()->builtins()->builtin_handle(trap_id),
......
......@@ -2895,7 +2895,10 @@ void CodeGenerator::AssembleArchTrap(Instruction* instr,
__ isolate()),
0);
__ LeaveFrame(StackFrame::WASM_COMPILED);
__ Ret();
CallDescriptor* descriptor = gen_->linkage()->GetIncomingDescriptor();
size_t pop_size = descriptor->StackParameterCount() * kPointerSize;
// Use rcx as a scratch register, we return anyways immediately.
__ Ret(static_cast<int>(pop_size), rcx);
} else {
gen_->AssembleSourcePosition(instr_);
__ Call(__ isolate()->builtins()->builtin_handle(trap_id),
......
......@@ -1668,6 +1668,17 @@ WASM_EXEC_TEST(Regress5874) {
r.Call();
}
WASM_EXEC_TEST(Regression_6858) {
REQUIRE(I64DivS);
// WasmRunner with 5 params and returns, which is the maximum.
WasmRunner<int64_t, int64_t, int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
int64_t dividend = 15;
int64_t divisor = 0;
int64_t filler = 34;
CHECK_TRAP64(r.Call(dividend, divisor, filler, filler));
}
#undef WASM_64
#undef MIPS
#undef REQUIRE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment