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

Side by Side Diff: src/typing-asm.cc

Issue 1564393003: Fixing asm validation of switch statements. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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 | « no previous file | test/cctest/test-asm-validator.cc » ('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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/typing-asm.h" 7 #include "src/typing-asm.h"
8 8
9 #include "src/ast/ast.h" 9 #include "src/ast/ast.h"
10 #include "src/ast/scopes.h" 10 #include "src/ast/scopes.h"
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 374
375 void AsmTyper::VisitSwitchStatement(SwitchStatement* stmt) { 375 void AsmTyper::VisitSwitchStatement(SwitchStatement* stmt) {
376 if (!in_function_) { 376 if (!in_function_) {
377 FAIL(stmt, "switch statement inside module body"); 377 FAIL(stmt, "switch statement inside module body");
378 } 378 }
379 RECURSE(VisitWithExpectation(stmt->tag(), cache_.kAsmSigned, 379 RECURSE(VisitWithExpectation(stmt->tag(), cache_.kAsmSigned,
380 "switch expression non-integer")); 380 "switch expression non-integer"));
381 ZoneList<CaseClause*>* clauses = stmt->cases(); 381 ZoneList<CaseClause*>* clauses = stmt->cases();
382 for (int i = 0; i < clauses->length(); ++i) { 382 for (int i = 0; i < clauses->length(); ++i) {
383 CaseClause* clause = clauses->at(i); 383 CaseClause* clause = clauses->at(i);
384 if (clause->is_default()) continue; 384 if (!clause->is_default()) {
385 Expression* label = clause->label(); 385 Expression* label = clause->label();
386 RECURSE(VisitWithExpectation(label, cache_.kAsmSigned, 386 RECURSE(VisitWithExpectation(label, cache_.kAsmSigned,
387 "case label non-integer")); 387 "case label non-integer"));
388 if (!label->IsLiteral()) FAIL(label, "non-literal case label"); 388 if (!label->IsLiteral()) FAIL(label, "non-literal case label");
389 Handle<Object> value = label->AsLiteral()->value(); 389 Handle<Object> value = label->AsLiteral()->value();
390 int32_t value32; 390 int32_t value32;
391 if (!value->ToInt32(&value32)) FAIL(label, "illegal case label value"); 391 if (!value->ToInt32(&value32)) FAIL(label, "illegal case label value");
392 }
392 // TODO(bradnelson): Detect duplicates. 393 // TODO(bradnelson): Detect duplicates.
393 ZoneList<Statement*>* stmts = clause->statements(); 394 ZoneList<Statement*>* stmts = clause->statements();
394 RECURSE(VisitStatements(stmts)); 395 RECURSE(VisitStatements(stmts));
395 } 396 }
396 } 397 }
397 398
398 399
399 void AsmTyper::VisitCaseClause(CaseClause* clause) { UNREACHABLE(); } 400 void AsmTyper::VisitCaseClause(CaseClause* clause) { UNREACHABLE(); }
400 401
401 402
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 525 }
525 526
526 IntersectResult(expr, then_type); 527 IntersectResult(expr, then_type);
527 } 528 }
528 529
529 530
530 void AsmTyper::VisitVariableProxy(VariableProxy* expr) { 531 void AsmTyper::VisitVariableProxy(VariableProxy* expr) {
531 Variable* var = expr->var(); 532 Variable* var = expr->var();
532 VariableInfo* info = GetVariableInfo(var, false); 533 VariableInfo* info = GetVariableInfo(var, false);
533 if (info == NULL || info->type == NULL) { 534 if (info == NULL || info->type == NULL) {
534 FAIL(expr, "unbound variable"); 535 if (var->mode() == TEMPORARY) {
536 SetType(var, Type::Any(zone()));
537 info = GetVariableInfo(var, false);
538 } else {
539 FAIL(expr, "unbound variable");
540 }
535 } 541 }
536 if (property_info_ != NULL) { 542 if (property_info_ != NULL) {
537 SetVariableInfo(var, property_info_); 543 SetVariableInfo(var, property_info_);
538 property_info_ = NULL; 544 property_info_ = NULL;
539 } 545 }
540 Type* type = Type::Intersect(info->type, expected_type_, zone()); 546 Type* type = Type::Intersect(info->type, expected_type_, zone());
541 if (type->Is(cache_.kAsmInt)) { 547 if (type->Is(cache_.kAsmInt)) {
542 type = cache_.kAsmInt; 548 type = cache_.kAsmInt;
543 } 549 }
544 info->type = type; 550 info->type = type;
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 1458
1453 1459
1454 void AsmTyper::VisitRewritableAssignmentExpression( 1460 void AsmTyper::VisitRewritableAssignmentExpression(
1455 RewritableAssignmentExpression* expr) { 1461 RewritableAssignmentExpression* expr) {
1456 RECURSE(Visit(expr->expression())); 1462 RECURSE(Visit(expr->expression()));
1457 } 1463 }
1458 1464
1459 1465
1460 } // namespace internal 1466 } // namespace internal
1461 } // namespace v8 1467 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-asm-validator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698