Commit 7f120ffb authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm] Add index argument to WasmDecoder.Pop(), improve error message

Change-Id: I991bcb5bc8a266ed4caa9ad4e8cb31fa6d30eef9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2275966Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68668}
parent 5ab06e7b
...@@ -2282,7 +2282,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -2282,7 +2282,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
} else if (check_result == kInvalidStack) { } else if (check_result == kInvalidStack) {
return 0; return 0;
} }
for (size_t i = 0; i < value_count; ++i) Pop(); for (int i = static_cast<int>(value_count) - 1; i >= 0; i--) Pop(i);
Value* pexception = Push(kWasmExnRef); Value* pexception = Push(kWasmExnRef);
*pexception = exception; *pexception = exception;
return 1 + imm.length; return 1 + imm.length;
...@@ -2291,7 +2291,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -2291,7 +2291,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
CHECK_PROTOTYPE_OPCODE(typed_funcref); CHECK_PROTOTYPE_OPCODE(typed_funcref);
BranchDepthImmediate<validate> imm(this, this->pc_ + 1); BranchDepthImmediate<validate> imm(this, this->pc_ + 1);
if (!this->Validate(this->pc_ + 1, imm, control_.size())) return 0; if (!this->Validate(this->pc_ + 1, imm, control_.size())) return 0;
Value ref_object = Pop(); Value ref_object = Pop(0);
if (this->failed()) return 0; if (this->failed()) return 0;
Control* c = control_at(imm.depth); Control* c = control_at(imm.depth);
TypeCheckBranchResult check_result = TypeCheckBranch(c, true); TypeCheckBranchResult check_result = TypeCheckBranch(c, true);
...@@ -2434,7 +2434,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -2434,7 +2434,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
} }
case kExprSelect: { case kExprSelect: {
Value cond = Pop(2, kWasmI32); Value cond = Pop(2, kWasmI32);
Value fval = Pop(); Value fval = Pop(1);
Value tval = Pop(0, fval.type); Value tval = Pop(0, fval.type);
ValueType type = tval.type == kWasmBottom ? fval.type : tval.type; ValueType type = tval.type == kWasmBottom ? fval.type : tval.type;
if (!VALIDATE(!type.is_reference_type())) { if (!VALIDATE(!type.is_reference_type())) {
...@@ -2597,7 +2597,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -2597,7 +2597,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
} }
case kExprRefIsNull: { case kExprRefIsNull: {
CHECK_PROTOTYPE_OPCODE(reftypes); CHECK_PROTOTYPE_OPCODE(reftypes);
Value value = Pop(); Value value = Pop(0);
Value* result = Push(kWasmI32); Value* result = Push(kWasmI32);
switch (value.type.kind()) { switch (value.type.kind()) {
case ValueType::kOptRef: case ValueType::kOptRef:
...@@ -2628,7 +2628,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -2628,7 +2628,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
} }
case kExprRefAsNonNull: { case kExprRefAsNonNull: {
CHECK_PROTOTYPE_OPCODE(typed_funcref); CHECK_PROTOTYPE_OPCODE(typed_funcref);
Value value = Pop(); Value value = Pop(0);
switch (value.type.kind()) { switch (value.type.kind()) {
case ValueType::kRef: { case ValueType::kRef: {
Value* result = Push(value.type); Value* result = Push(value.type);
...@@ -2674,7 +2674,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -2674,7 +2674,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
return 1 + imm.length; return 1 + imm.length;
} }
case kExprDrop: { case kExprDrop: {
Value value = Pop(); Value value = Pop(0);
CALL_INTERFACE_IF_REACHABLE(Drop, value); CALL_INTERFACE_IF_REACHABLE(Drop, value);
return 1; return 1;
} }
...@@ -3308,7 +3308,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -3308,7 +3308,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
case kExprStructNewWithRtt: { case kExprStructNewWithRtt: {
StructIndexImmediate<validate> imm(this, this->pc_ + 2); StructIndexImmediate<validate> imm(this, this->pc_ + 2);
if (!this->Validate(this->pc_, imm)) return 0; if (!this->Validate(this->pc_, imm)) return 0;
Value rtt = Pop(); Value rtt = Pop(imm.struct_type->field_count());
if (!VALIDATE(rtt.type.kind() == ValueType::kRtt)) { if (!VALIDATE(rtt.type.kind() == ValueType::kRtt)) {
this->errorf( this->errorf(
this->pc_ + 2, this->pc_ + 2,
...@@ -3484,7 +3484,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -3484,7 +3484,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
// implement them here. // implement them here.
HeapTypeImmediate<validate> imm(this->enabled_, this, this->pc_ + 2); HeapTypeImmediate<validate> imm(this->enabled_, this, this->pc_ + 2);
if (!this->Validate(this->pc_ + 2, imm)) return 0; if (!this->Validate(this->pc_ + 2, imm)) return 0;
Value parent = Pop(); Value parent = Pop(0);
// TODO(7748): Consider exposing "IsSubtypeOfHeap(HeapType t1, t2)" so // TODO(7748): Consider exposing "IsSubtypeOfHeap(HeapType t1, t2)" so
// we can avoid creating (ref heaptype) wrappers here. // we can avoid creating (ref heaptype) wrappers here.
if (!VALIDATE(parent.type.kind() == ValueType::kRtt && if (!VALIDATE(parent.type.kind() == ValueType::kRtt &&
...@@ -3517,7 +3517,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -3517,7 +3517,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
"ref.test: rtt type must be subtype of object type"); "ref.test: rtt type must be subtype of object type");
return 0; return 0;
} }
Value rtt = Pop(); Value rtt = Pop(1);
if (!VALIDATE(rtt.type.kind() == ValueType::kRtt && if (!VALIDATE(rtt.type.kind() == ValueType::kRtt &&
rtt.type.heap_type() == rtt_type.type)) { rtt.type.heap_type() == rtt_type.type)) {
this->errorf( this->errorf(
...@@ -3546,7 +3546,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -3546,7 +3546,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
"ret.cast: rtt type must be subtype of object type"); "ret.cast: rtt type must be subtype of object type");
return 0; return 0;
} }
Value rtt = Pop(); Value rtt = Pop(1);
if (!VALIDATE(rtt.type.kind() == ValueType::kRtt && if (!VALIDATE(rtt.type.kind() == ValueType::kRtt &&
rtt.type.heap_type() == rtt_type.type)) { rtt.type.heap_type() == rtt_type.type)) {
this->errorf( this->errorf(
...@@ -3757,7 +3757,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -3757,7 +3757,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
} }
V8_INLINE Value Pop(int index, ValueType expected) { V8_INLINE Value Pop(int index, ValueType expected) {
Value val = Pop(); Value val = Pop(index);
if (!VALIDATE(IsSubtypeOf(val.type, expected, this->module_) || if (!VALIDATE(IsSubtypeOf(val.type, expected, this->module_) ||
val.type == kWasmBottom || expected == kWasmBottom)) { val.type == kWasmBottom || expected == kWasmBottom)) {
this->errorf(val.pc, "%s[%d] expected type %s, found %s of type %s", this->errorf(val.pc, "%s[%d] expected type %s, found %s of type %s",
...@@ -3768,14 +3768,16 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -3768,14 +3768,16 @@ class WasmFullDecoder : public WasmDecoder<validate> {
return val; return val;
} }
V8_INLINE Value Pop() { V8_INLINE Value Pop(int index) {
DCHECK(!control_.empty()); DCHECK(!control_.empty());
uint32_t limit = control_.back().stack_depth; uint32_t limit = control_.back().stack_depth;
if (stack_.size() <= limit) { if (stack_.size() <= limit) {
// Popping past the current control start in reachable code. // Popping past the current control start in reachable code.
if (!VALIDATE(control_.back().unreachable())) { if (!VALIDATE(control_.back().unreachable())) {
this->errorf(this->pc_, "%s found empty stack", this->errorf(
SafeOpcodeNameAt(this->pc_)); this->pc_,
"not enough arguments on the stack for %s, expected %d more",
SafeOpcodeNameAt(this->pc_), index + 1);
} }
return UnreachableValue(this->pc_); return UnreachableValue(this->pc_);
} }
......
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