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

Unified Diff: src/asmjs/asm-typer.cc

Issue 2172603002: [wasm] ASM-2-WASM. Enforces switch default clause appearing last. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/cctest/asmjs/test-asm-typer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/asmjs/asm-typer.cc
diff --git a/src/asmjs/asm-typer.cc b/src/asmjs/asm-typer.cc
index 165ef9e148faf65e0b4e29701d7ba9b5edf97d07..076cd4db9da0084a71087c564a1dab394aed04b3 100644
--- a/src/asmjs/asm-typer.cc
+++ b/src/asmjs/asm-typer.cc
@@ -1255,17 +1255,23 @@ AsmType* AsmTyper::ValidateSwitchStatement(SwitchStatement* stmt) {
FAIL(stmt, "Switch tag must be signed.");
}
- bool has_default = false;
-
+ int default_pos = kNoSourcePosition;
+ int last_case_pos = kNoSourcePosition;
ZoneSet<int32_t> cases_seen(zone_);
for (auto* a_case : *stmt->cases()) {
if (a_case->is_default()) {
- CHECK(!has_default);
+ CHECK(default_pos == kNoSourcePosition);
RECURSE(ValidateDefault(a_case));
- has_default = true;
+ default_pos = a_case->position();
continue;
}
+ if (last_case_pos == kNoSourcePosition) {
+ last_case_pos = a_case->position();
+ } else {
+ last_case_pos = std::max(last_case_pos, a_case->position());
+ }
+
int32_t case_lbl;
RECURSE(ValidateCase(a_case, &case_lbl));
auto case_lbl_pos = cases_seen.find(case_lbl);
@@ -1283,6 +1289,11 @@ AsmType* AsmTyper::ValidateSwitchStatement(SwitchStatement* stmt) {
}
}
+ if (last_case_pos != kNoSourcePosition && default_pos != kNoSourcePosition &&
+ default_pos < last_case_pos) {
+ FAIL(stmt, "Switch default must appear last.");
+ }
+
return AsmType::Void();
}
« no previous file with comments | « no previous file | test/cctest/asmjs/test-asm-typer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698