diff options
-rw-r--r-- | src/ir/type-updating.cpp | 4 | ||||
-rw-r--r-- | test/lit/passes/flatten.wast | 22 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/ir/type-updating.cpp b/src/ir/type-updating.cpp index 54a83aa49..312540b53 100644 --- a/src/ir/type-updating.cpp +++ b/src/ir/type-updating.cpp @@ -37,6 +37,10 @@ void handleNonNullableLocals(Function* func, Module& wasm) { Builder builder(wasm); for (auto** getp : FindAllPointers<LocalGet>(func->body).list) { auto* get = (*getp)->cast<LocalGet>(); + if (!func->isVar(get->index)) { + // We do not need to process params, which can legally be non-nullable. + continue; + } auto type = func->getLocalType(get->index); if (type.isRef() && !type.isNullable()) { // The get should now return a nullable value, and a ref.as_non_null diff --git a/test/lit/passes/flatten.wast b/test/lit/passes/flatten.wast new file mode 100644 index 000000000..f734996a5 --- /dev/null +++ b/test/lit/passes/flatten.wast @@ -0,0 +1,22 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. +;; RUN: wasm-opt %s -all --flatten -S -o - | filecheck %s + +(module + (type $simplefunc (func)) + ;; CHECK: (func $0 (param $0 (ref $simplefunc)) (result (ref $simplefunc)) + ;; CHECK-NEXT: (local $1 (ref null $simplefunc)) + ;; CHECK-NEXT: (local.set $1 + ;; CHECK-NEXT: (local.get $0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (return + ;; CHECK-NEXT: (ref.as_non_null + ;; CHECK-NEXT: (local.get $1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $0 (param $0 (ref $simplefunc)) (result (ref $simplefunc)) + ;; a local.get of a non-nullable param is ok, and does not need to be + ;; modified + (local.get $0) + ) +) |