summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tools/wasm-merge.cpp16
-rw-r--r--test/lit/merge/import_cycle.wat14
2 files changed, 14 insertions, 16 deletions
diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp
index 47dd1e111..9fe97669b 100644
--- a/src/tools/wasm-merge.cpp
+++ b/src/tools/wasm-merge.cpp
@@ -235,16 +235,20 @@ void updateNames(Module& wasm, KindNameUpdates& kindNameUpdates) {
}
private:
- Name resolveName(NameUpdates& updates, const Name newName) {
- // Iteratively lookup the updated name
- // We detect loops to ensure termination
+ Name resolveName(NameUpdates& updates, Name newName, Name oldName) {
+ // Iteratively lookup the updated name.
std::set<Name> visited;
- Name name = newName;
+ auto name = newName;
while (1) {
auto iter = updates.find(name);
- if (iter == updates.end() || visited.find(name) != visited.end()) {
+ if (iter == updates.end()) {
return name;
}
+ if (visited.count(name)) {
+ // This is a loop of imports, which means we cannot resolve a useful
+ // name. Report an error.
+ Fatal() << "wasm-merge: infinite loop of imports on " << oldName;
+ }
visited.insert(name);
name = iter->second;
}
@@ -258,7 +262,7 @@ void updateNames(Module& wasm, KindNameUpdates& kindNameUpdates) {
auto& nameUpdates = iter->second;
auto iter2 = nameUpdates.find(name);
if (iter2 != nameUpdates.end()) {
- name = resolveName(nameUpdates, iter2->second);
+ name = resolveName(nameUpdates, iter2->second, name);
}
}
} nameMapper(kindNameUpdates);
diff --git a/test/lit/merge/import_cycle.wat b/test/lit/merge/import_cycle.wat
index 0261eabc5..84d6017b9 100644
--- a/test/lit/merge/import_cycle.wat
+++ b/test/lit/merge/import_cycle.wat
@@ -1,16 +1,10 @@
-;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
-;; RUN: wasm-merge %s first %s.second second -S -o - | filecheck %s
+;; RUN: not wasm-merge %s first %s.second second 2>&1 | filecheck %s
-;; Test that wasm-merge terminates when there are importation cycles
+;; Test that wasm-merge terminates with an error when there is an import cycle.
-(module
- ;; CHECK: (type $none_=>_none (func))
+;; CHECK: Fatal: wasm-merge: infinite loop of imports on f
- ;; CHECK: (import "second" "g" (func $f))
+(module
(import "second" "g" (func $f))
- ;; CHECK: (import "first" "f" (func $f_1))
-
- ;; CHECK: (export "f" (func $f_1))
(export "f" (func $f))
)
-;; CHECK: (export "g" (func $f))