From 404846caeaf2f866aeffc3523403c2272e323dac Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 9 Nov 2015 20:15:20 -0800 Subject: handle some switch errors, get the switch testcase passing --- src/wasm-s-parser.h | 1 + src/wasm.h | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index f71d65707..642a28606 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1040,6 +1040,7 @@ private: for (; i < s.size(); i++) { Element& curr = *s[i]; assert(curr[0]->str() == CASE); + if (curr.size() < 2) onError(); ret->cases.emplace_back(curr[1]->str(), makeMaybeBlock(curr, 2, curr.size())); } ret->updateCaseMap(); diff --git a/src/wasm.h b/src/wasm.h index 0afb955a9..c292e6bc6 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1319,21 +1319,20 @@ bool Module::validateFunction(Function *func) { if (!validateAlignment(curr->align)) valid = false; } void visitSwitch(Switch *curr) override { -std::cerr << "validate switch "; -curr->doPrint(std::cerr, 0) << "\n"; std::set inTable; for (auto target : curr->targets) { if (target.is()) { inTable.insert(target); -std::cerr << "in table: " << target << '\n'; } } for (auto& c : curr->cases) { -std::cerr << "chack: " << c.name.is() << " : " << (c.name.is() ? c.name.str : "ASSDAS") << '\n'; if (c.name.is() && inTable.find(c.name) == inTable.end()) { valid = false; } } + if (curr->default_.is() && inTable.find(curr->default_) == inTable.end()) { + valid = false; + } } bool validateAlignment(size_t align) { -- cgit v1.2.3