diff options
author | Alon Zakai <azakai@google.com> | 2021-10-11 17:37:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-11 17:37:23 -0700 |
commit | ecda340b791be6c0a31c7dd290a682244aff3e89 (patch) | |
tree | 93d97df579919bb6fef6e796d949ebd9f763cc6f /src | |
parent | 072c60c9314ca37f0f4a9393bb81dabd1be5a6b5 (diff) | |
download | binaryen-ecda340b791be6c0a31c7dd290a682244aff3e89.tar.gz binaryen-ecda340b791be6c0a31c7dd290a682244aff3e89.tar.bz2 binaryen-ecda340b791be6c0a31c7dd290a682244aff3e89.zip |
Fix tee/as-non-null reordering when writing to a non-nullable param (#4232)
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 97f1cb756..ed3d474d9 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -1054,8 +1054,12 @@ struct OptimizeInstructions // can't remove or move a ref.as_non_null flowing into a local.set/tee, and // (2) even if the local were nullable, if we change things we might prevent // the LocalSubtyping pass from turning it into a non-nullable local later. + // Note that we must also check if this local is nullable regardless, as a + // parameter might be non-nullable even if nullable locals are disallowed + // (as that just affects vars, and not params). if (auto* as = curr->value->dynCast<RefAs>()) { - if (as->op == RefAsNonNull && !getModule()->features.hasGCNNLocals()) { + if (as->op == RefAsNonNull && !getModule()->features.hasGCNNLocals() && + getFunction()->getLocalType(curr->index).isNullable()) { // (local.tee (ref.as_non_null ..)) // => // (ref.as_non_null (local.tee ..)) |