From ab66e9ab1210a87d1db8ebe93cf8463eafe34e33 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Wed, 3 Nov 2021 14:44:59 -0700 Subject: Fix RTTs for RTT-less instructions (#4294) Allocation and cast instructions without explicit RTTs should use the canonical RTTs for the given types. Furthermore, the RTTs for nominal types should reflect the static type hierarchy. Previously, however, we implemented allocations and casts without RTTs using an alternative system that only used static types rather than RTT values. This alternative system would work fine in a world without first-class RTTs, but it did not properly allow mixing instructions that use RTTs and instructions that do not use RTTs as intended by the M4 GC spec. This PR fixes the issue by using canonical RTTs where appropriate and cleans up the relevant casting code using std::variant. --- src/wasm/wasm-validator.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index f8669961c..bb0e99cc2 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2361,7 +2361,10 @@ void FunctionValidator::visitRttCanon(RttCanon* curr) { getModule()->features.hasGC(), curr, "rtt.canon requires gc to be enabled"); shouldBeTrue(curr->type.isRtt(), curr, "rtt.canon must have RTT type"); auto rtt = curr->type.getRtt(); - shouldBeEqual(rtt.depth, Index(0), curr, "rtt.canon has a depth of 0"); + shouldBeEqual(rtt.depth, + Index(curr->type.getHeapType().getDepth()), + curr, + "rtt.canon must have the depth of its heap type"); } void FunctionValidator::visitRttSub(RttSub* curr) { -- cgit v1.2.3