Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: src/wasm/function-body-decoder.cc

Issue 2628203003: Reland of [wasm] Enforce that function bodies end with the \"end\" opcode. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/asmjs/asm-wasm-builder.cc ('k') | src/wasm/wasm-macro-gen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/signature.h" 5 #include "src/signature.h"
6 6
7 #include "src/bit-vector.h" 7 #include "src/bit-vector.h"
8 #include "src/flags.h" 8 #include "src/flags.h"
9 #include "src/handles.h" 9 #include "src/handles.h"
10 #include "src/zone/zone-containers.h" 10 #include "src/zone/zone-containers.h"
(...skipping 21 matching lines...) Expand all
32 #endif 32 #endif
33 33
34 #define CHECK_PROTOTYPE_OPCODE(flag) \ 34 #define CHECK_PROTOTYPE_OPCODE(flag) \
35 if (module_ != nullptr && module_->origin == kAsmJsOrigin) { \ 35 if (module_ != nullptr && module_->origin == kAsmJsOrigin) { \
36 error("Opcode not supported for asmjs modules"); \ 36 error("Opcode not supported for asmjs modules"); \
37 } \ 37 } \
38 if (!FLAG_##flag) { \ 38 if (!FLAG_##flag) { \
39 error("Invalid opcode (enable with --" #flag ")"); \ 39 error("Invalid opcode (enable with --" #flag ")"); \
40 break; \ 40 break; \
41 } 41 }
42 // TODO(titzer): this is only for intermediate migration.
43 #define IMPLICIT_FUNCTION_END 1
44 42
45 // An SsaEnv environment carries the current local variable renaming 43 // An SsaEnv environment carries the current local variable renaming
46 // as well as the current effect and control dependency in the TF graph. 44 // as well as the current effect and control dependency in the TF graph.
47 // It maintains a control state that tracks whether the environment 45 // It maintains a control state that tracks whether the environment
48 // is reachable, has reached a control end, or has been merged. 46 // is reachable, has reached a control end, or has been merged.
49 struct SsaEnv { 47 struct SsaEnv {
50 enum State { kControlEnd, kUnreachable, kReached, kMerged }; 48 enum State { kControlEnd, kUnreachable, kReached, kMerged };
51 49
52 State state; 50 State state;
53 TFNode* control; 51 TFNode* control;
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 return false; 484 return false;
487 } 485 }
488 486
489 DCHECK_EQ(0, local_types_->size()); 487 DCHECK_EQ(0, local_types_->size());
490 WasmDecoder::DecodeLocals(this, sig_, local_types_); 488 WasmDecoder::DecodeLocals(this, sig_, local_types_);
491 InitSsaEnv(); 489 InitSsaEnv();
492 DecodeFunctionBody(); 490 DecodeFunctionBody();
493 491
494 if (failed()) return TraceFailed(); 492 if (failed()) return TraceFailed();
495 493
496 #if IMPLICIT_FUNCTION_END 494 if (!control_.empty()) {
497 // With implicit end support (old style), the function block 495 // Generate a better error message whether the unterminated control
498 // remains on the stack. Other control blocks are an error. 496 // structure is the function body block or an innner structure.
499 if (control_.size() > 1) { 497 if (control_.size() > 1) {
500 error(pc_, control_.back().pc, "unterminated control structure"); 498 error(pc_, control_.back().pc, "unterminated control structure");
499 } else {
500 error("function body must end with \"end\" opcode.");
501 }
501 return TraceFailed(); 502 return TraceFailed();
502 } 503 }
503 504
504 // Assume an implicit end to the function body block.
505 if (control_.size() == 1) {
506 Control* c = &control_.back();
507 if (ssa_env_->go()) {
508 FallThruTo(c);
509 }
510
511 if (c->end_env->go()) {
512 // Push the end values onto the stack.
513 stack_.resize(c->stack_depth);
514 if (c->merge.arity == 1) {
515 stack_.push_back(c->merge.vals.first);
516 } else {
517 for (unsigned i = 0; i < c->merge.arity; i++) {
518 stack_.push_back(c->merge.vals.array[i]);
519 }
520 }
521
522 TRACE(" @%-8d #xx:%-20s|", startrel(pc_), "ImplicitReturn");
523 SetEnv("function:end", c->end_env);
524 DoReturn();
525 TRACE("\n");
526 }
527 }
528 #else
529 if (!control_.empty()) {
530 error(pc_, control_.back().pc, "unterminated control structure");
531 return TraceFailed();
532 }
533
534 if (!last_end_found_) { 505 if (!last_end_found_) {
535 error("function body must end with \"end\" opcode."); 506 error("function body must end with \"end\" opcode.");
536 return false; 507 return false;
537 } 508 }
538 #endif
539 509
540 if (FLAG_trace_wasm_decode_time) { 510 if (FLAG_trace_wasm_decode_time) {
541 double ms = decode_timer.Elapsed().InMillisecondsF(); 511 double ms = decode_timer.Elapsed().InMillisecondsF();
542 PrintF("wasm-decode %s (%0.3f ms)\n\n", ok() ? "ok" : "failed", ms); 512 PrintF("wasm-decode %s (%0.3f ms)\n\n", ok() ? "ok" : "failed", ms);
543 } else { 513 } else {
544 TRACE("wasm-decode %s\n\n", ok() ? "ok" : "failed"); 514 TRACE("wasm-decode %s\n\n", ok() ? "ok" : "failed");
545 } 515 }
546 516
547 return true; 517 return true;
548 } 518 }
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after
2056 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, 2026 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,
2057 const byte* start, const byte* end) { 2027 const byte* start, const byte* end) {
2058 Decoder decoder(start, end); 2028 Decoder decoder(start, end);
2059 return WasmDecoder::AnalyzeLoopAssignment(&decoder, start, 2029 return WasmDecoder::AnalyzeLoopAssignment(&decoder, start,
2060 static_cast<int>(num_locals), zone); 2030 static_cast<int>(num_locals), zone);
2061 } 2031 }
2062 2032
2063 } // namespace wasm 2033 } // namespace wasm
2064 } // namespace internal 2034 } // namespace internal
2065 } // namespace v8 2035 } // namespace v8
OLDNEW
« no previous file with comments | « src/asmjs/asm-wasm-builder.cc ('k') | src/wasm/wasm-macro-gen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698