From e4f61e6296f05a2f3600c53aa466cb342c1603a6 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 22 Sep 2021 11:38:10 -0700 Subject: Properly error on bad function names in text format (#4177) --- src/wasm/wasm-s-parser.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/wasm/wasm-s-parser.cpp') diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 3cfe90e26..697e4e58d 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -1236,6 +1236,15 @@ Type SExpressionWasmBuilder::stringToLaneType(const char* str) { return Type::none; } +HeapType SExpressionWasmBuilder::getFunctionType(Name name, Element& s) { + auto iter = functionTypes.find(name); + if (iter == functionTypes.end()) { + throw ParseException( + "invalid call target: " + std::string(name.str), s.line, s.col); + } + return iter->second; +} + Function::DebugLocation SExpressionWasmBuilder::getDebugLocation(const SourceLocation& loc) { IString file = loc.filename; @@ -2259,7 +2268,7 @@ Expression* SExpressionWasmBuilder::makeCall(Element& s, bool isReturn) { auto target = getFunctionName(*s[1]); auto ret = allocator.alloc(); ret->target = target; - ret->type = functionTypes[ret->target].getSignature().results; + ret->type = getFunctionType(ret->target, s).getSignature().results; parseCallOperands(s, 2, s.size(), ret); ret->isReturn = isReturn; ret->finalize(); @@ -2396,7 +2405,7 @@ Expression* SExpressionWasmBuilder::makeRefFunc(Element& s) { ret->func = func; // To support typed function refs, we give the reference not just a general // funcref, but a specific subtype with the actual signature. - ret->finalize(Type(functionTypes[func], NonNullable)); + ret->finalize(Type(getFunctionType(func, s), NonNullable)); return ret; } -- cgit v1.2.3