diff options
author | Thomas Lively <tlively@google.com> | 2023-01-19 12:56:42 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-19 10:56:42 -0800 |
commit | 9956bd3895741c09964f0d92bbcebe9131f15f88 (patch) | |
tree | ace3b7a6c1270f2c8015ee7f2b6f952de27c8b72 /src | |
parent | 0d6d317d44d13240dfc9427f8f32c1299449287b (diff) | |
download | binaryen-9956bd3895741c09964f0d92bbcebe9131f15f88.tar.gz binaryen-9956bd3895741c09964f0d92bbcebe9131f15f88.tar.bz2 binaryen-9956bd3895741c09964f0d92bbcebe9131f15f88.zip |
[Wasm GC] Do not merge supertypes into subtypes (#5439)
In TypeMerging we previously merged all subsequent types in a refined partition
into whichever type happened to be first in the partition, but when that first
type happened to be a subtype of one of the other types in the partition, that
would cause type-updating.cpp to try to update that subtype's supertype to be
itself, causing an assertion failure.
Fix the problem by ensuring that the merge target is not a subtype of any other
types in the partition.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/TypeMerging.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/passes/TypeMerging.cpp b/src/passes/TypeMerging.cpp index 6f39d586f..5623ecdb9 100644 --- a/src/passes/TypeMerging.cpp +++ b/src/passes/TypeMerging.cpp @@ -280,10 +280,15 @@ void TypeMerging::run(Module* module_) { // The types we can merge mapped to the type we are merging them into. TypeUpdates merges; - // Merge each refined partition into a single type. + // Merge each refined partition into a single type. We should only merge into + // supertypes or siblings because if we try to merge into a subtype then we + // will accidentally set that subtype to be its own supertype. for (const auto& partition : refinedPartitions) { - for (size_t i = 1; i < partition.size(); ++i) { - merges[partition[i]] = partition[0]; + auto target = *HeapTypeOrdering::SupertypesFirst(partition).begin(); + for (auto type : partition) { + if (type != target) { + merges[type] = target; + } } } |