diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2021-08-02 17:58:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-02 17:58:37 -0400 |
commit | f1136a48518378eb3454f5da4f05c686755b5819 (patch) | |
tree | d6cfa3e000db51b5c5c70d5a5b34f0cf95df6e4d | |
parent | 8aca1a3ccd1d3a0aaa72770f1412d395468713e3 (diff) | |
download | binaryen-f1136a48518378eb3454f5da4f05c686755b5819.tar.gz binaryen-f1136a48518378eb3454f5da4f05c686755b5819.tar.bz2 binaryen-f1136a48518378eb3454f5da4f05c686755b5819.zip |
Fix a bug in nominal LUB calculation (#4046)
The wrong variable was null checked, leading to segfaults.
-rw-r--r-- | src/wasm/wasm-type.cpp | 2 | ||||
-rw-r--r-- | test/example/type-builder-nominal.cpp | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index d4f38cc2c..998d1a96b 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -1512,7 +1512,7 @@ HeapType TypeBounder::lub(HeapType a, HeapType b) { } currA = nextA; } - if (currB) { + if (nextB) { if (!seen.insert(nextB).second) { return HeapType(uintptr_t(nextB)); } diff --git a/test/example/type-builder-nominal.cpp b/test/example/type-builder-nominal.cpp index f3eed5810..1904bb7ee 100644 --- a/test/example/type-builder-nominal.cpp +++ b/test/example/type-builder-nominal.cpp @@ -323,6 +323,20 @@ void test_subtypes() { } { + // Subtype declarations, but still no subtypes + std::vector<HeapType> built; + { + TypeBuilder builder(3); + builder[0].subTypeOf(builder[1]); + builder[0] = Struct{}; + builder[1] = Struct{}; + builder[2] = Struct{}; + built = builder.build(); + } + assert(LUB(built[0], built[2]) == HeapType::data); + } + + { // Subtyping of identical types std::vector<HeapType> built; { |