diff options
author | Alon Zakai <azakai@google.com> | 2024-07-25 10:17:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-25 10:17:42 -0700 |
commit | d903dd30f6426b8eb07605cae01baf4158364e2d (patch) | |
tree | 6c67cea92a4381e08a7823360045a66f244495bd /src/passes/TupleOptimization.cpp | |
parent | 017b473f05b8dde4da8aadd154e6d2606071d2cb (diff) | |
download | binaryen-d903dd30f6426b8eb07605cae01baf4158364e2d.tar.gz binaryen-d903dd30f6426b8eb07605cae01baf4158364e2d.tar.bz2 binaryen-d903dd30f6426b8eb07605cae01baf4158364e2d.zip |
TupleOptimization: Properly handle subtyping in copies (#6786)
We used the target's type for the read from the source, but due to
subtyping those might be different.
Found by the fuzzer.
Diffstat (limited to 'src/passes/TupleOptimization.cpp')
-rw-r--r-- | src/passes/TupleOptimization.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/passes/TupleOptimization.cpp b/src/passes/TupleOptimization.cpp index 25da1c5ec..ca704f1a3 100644 --- a/src/passes/TupleOptimization.cpp +++ b/src/passes/TupleOptimization.cpp @@ -25,7 +25,7 @@ // (tuple.extract 3 0 // (local.get $tuple))) // -// If there are no other uses, then we just need one of the three lanes. By +// If there are no other uses, then we just need one of the three elements. By // lowing them to three separate locals, other passes can remove the other two. // // Specifically, this pass seeks out tuple locals that have these properties: @@ -320,8 +320,13 @@ struct TupleOptimization : public WalkerPass<PostWalker<TupleOptimization>> { // we were confused earlier and the target should not be. assert(sourceBase); + // The source and target may have different element types due to + // subtyping (but their sizes must be equal). + auto sourceType = value->type; + assert(sourceType.size() == type.size()); + for (Index i = 0; i < type.size(); i++) { - auto* get = builder.makeLocalGet(sourceBase + i, type[i]); + auto* get = builder.makeLocalGet(sourceBase + i, sourceType[i]); contents.push_back(builder.makeLocalSet(targetBase + i, get)); } replace(builder.makeBlock(contents)); |