diff options
Diffstat (limited to 'src/wasm/wasm-validator.cpp')
-rw-r--r-- | src/wasm/wasm-validator.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 5534eb7b9..85e2193fa 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -559,6 +559,24 @@ void WasmValidator::visitFunction(Function *curr) { shouldBeTrue(breakTargets.empty(), curr->body, "all named break targets must exist"); returnType = unreachable; labelNames.clear(); + // expressions must not be seen more than once + struct Walker : public PostWalker<Walker, UnifiedExpressionVisitor<Walker>> { + std::unordered_set<Expression*>& seen; + std::vector<Expression*> dupes; + + Walker(std::unordered_set<Expression*>& seen) : seen(seen) {} + + void visitExpression(Expression* curr) { + bool inserted; + std::tie(std::ignore, inserted) = seen.insert(curr); + if (!inserted) dupes.push_back(curr); + } + }; + Walker walker(seenExpressions); + walker.walk(curr->body); + for (auto* bad : walker.dupes) { + fail("expression seen more than once in the tree", bad); + } } static bool checkOffset(Expression* curr, Address add, Address max) { |