diff options
author | Alon Zakai <azakai@google.com> | 2024-02-14 14:23:08 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-14 14:23:08 -0800 |
commit | 36d20933da2267068f4e5d4bb3c5a1adb9360f26 (patch) | |
tree | 9c197827099cd7afb1f3b65a9d0411167a8d943f /src | |
parent | 99e54a0b484e13b84dc49060f5f40ed8ad9ac90a (diff) | |
download | binaryen-36d20933da2267068f4e5d4bb3c5a1adb9360f26.tar.gz binaryen-36d20933da2267068f4e5d4bb3c5a1adb9360f26.tar.bz2 binaryen-36d20933da2267068f4e5d4bb3c5a1adb9360f26.zip |
StringLowering: Properly handle nullable inputs to StringAs (#6307)
StringAs's output must be non-nullable, so add a cast.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/StringLowering.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/passes/StringLowering.cpp b/src/passes/StringLowering.cpp index a0002fcf6..85e75f705 100644 --- a/src/passes/StringLowering.cpp +++ b/src/passes/StringLowering.cpp @@ -35,6 +35,7 @@ #include "ir/module-utils.h" #include "ir/names.h" #include "ir/type-updating.h" +#include "ir/utils.h" #include "pass.h" #include "support/json.h" #include "wasm-builder.h" @@ -360,7 +361,13 @@ struct StringLowering : public StringGathering { void visitStringAs(StringAs* curr) { // There is no difference between strings and views with imported // strings: they are all just JS strings, so no conversion is needed. - replaceCurrent(curr->ref); + // However, we must keep the same nullability: the output of StringAs + // must be non-nullable. + auto* ref = curr->ref; + if (ref->type.isNullable()) { + ref = Builder(*getModule()).makeRefAs(RefAsNonNull, ref); + } + replaceCurrent(ref); } void visitStringEncode(StringEncode* curr) { @@ -468,6 +475,9 @@ struct StringLowering : public StringGathering { Replacer replacer(*this); replacer.run(getPassRunner(), module); replacer.walkModuleCode(module); + + // ReFinalize to apply changes to parents. + ReFinalize().run(getPassRunner(), module); } }; |