summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-s-parser.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-09-22 11:38:10 -0700
committerGitHub <noreply@github.com>2021-09-22 11:38:10 -0700
commite4f61e6296f05a2f3600c53aa466cb342c1603a6 (patch)
tree8515c2310d4e498411eb19bf5e625c72bc0a8305 /src/wasm/wasm-s-parser.cpp
parent6c1724ce80d6e8b9daacd352c4a9dc4c98af6b03 (diff)
downloadbinaryen-e4f61e6296f05a2f3600c53aa466cb342c1603a6.tar.gz
binaryen-e4f61e6296f05a2f3600c53aa466cb342c1603a6.tar.bz2
binaryen-e4f61e6296f05a2f3600c53aa466cb342c1603a6.zip
Properly error on bad function names in text format (#4177)
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r--src/wasm/wasm-s-parser.cpp13
1 files changed, 11 insertions, 2 deletions
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<Call>();
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;
}