diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/gtest/possible-contents.cpp | 31 | ||||
-rw-r--r-- | test/lit/passes/gufa-refs.wast | 78 |
2 files changed, 107 insertions, 2 deletions
diff --git a/test/gtest/possible-contents.cpp b/test/gtest/possible-contents.cpp index 7b8f0c4a8..802d08c18 100644 --- a/test/gtest/possible-contents.cpp +++ b/test/gtest/possible-contents.cpp @@ -854,6 +854,33 @@ TEST_F(PossibleContentsTest, TestOracleManyTypes) { auto bodyContents = oracle.getContents(ResultLocation{wasm->getFunction("foo"), 0}); ASSERT_TRUE(bodyContents.isConeType()); - EXPECT_TRUE(bodyContents.getType().getHeapType() == HeapType::data); - EXPECT_TRUE(bodyContents.getCone().depth == 1); + EXPECT_EQ(bodyContents.getType().getHeapType(), HeapType::data); + EXPECT_EQ(bodyContents.getCone().depth, Index(1)); +} + +TEST_F(PossibleContentsTest, TestOracleNoFullCones) { + // PossibleContents should be normalized, so we never have full cones (depth + // infinity). + auto wasm = parse(R"( + (module + (type $A (struct_subtype (field i32) data)) + (type $B (struct_subtype (field i32) $A)) + (type $C (struct_subtype (field i32) $B)) + (func $foo (export "foo") + ;; Note we must declare $C so that $B and $C have uses and are not + ;; removed automatically from consideration. + (param $a (ref $A)) (param $c (ref $C)) + (result (ref any)) + (local.get $a) + ) + ) + )"); + ContentOracle oracle(*wasm); + // The function is exported, and all we know about the parameter $a is that it + // is some subtype of $A. This is normalized to depth 2 because that is the + // actual depth of subtypes. + auto bodyContents = + oracle.getContents(ResultLocation{wasm->getFunction("foo"), 0}); + ASSERT_TRUE(bodyContents.isConeType()); + EXPECT_EQ(bodyContents.getCone().depth, Index(2)); } diff --git a/test/lit/passes/gufa-refs.wast b/test/lit/passes/gufa-refs.wast index ec58e10a0..a5ef2735a 100644 --- a/test/lit/passes/gufa-refs.wast +++ b/test/lit/passes/gufa-refs.wast @@ -5209,6 +5209,8 @@ ;; CHECK: (type $none_=>_ref|$A| (func_subtype (result (ref $A)) func)) + ;; CHECK: (type $none_=>_none (func_subtype func)) + ;; CHECK: (import "a" "b" (global $A (ref $A))) (import "a" "b" (global $A (ref $A))) @@ -5324,4 +5326,80 @@ ) ) ) + + ;; CHECK: (func $filtering (type $none_=>_none) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block $B (result (ref $B)) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (br_on_cast_static $B $B + ;; CHECK-NEXT: (struct.new $A + ;; CHECK-NEXT: (i32.const 100) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result i32) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block $A (result (ref $A)) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (br_on_cast_static $A $A + ;; CHECK-NEXT: (struct.new $A + ;; CHECK-NEXT: (i32.const 200) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $filtering + ;; Check for filtering of values by the declared type in the wasm. We do not + ;; have specific filtering or flowing for br_on_* yet, so it will always + ;; send the value to the branch target. But the target has a declared type + ;; of $B, which means the exact $A gets filtered out, and nothing remains, + ;; so we can append an unreachable. + ;; + ;; When we add filtering/flowing for br_on_* this test should continue to + ;; pass and only the comment will need to be updated, so if you are reading + ;; this and it is stale, please fix that :) + (drop + (block $B (result (ref $B)) + (drop + (br_on_cast_static $B $B + (struct.new $A + (i32.const 100) + ) + ) + ) + (unreachable) + ) + ) + ;; But casting to $A will succeed, so the block is reachable, and also the + ;; cast will return 1. + (drop + (ref.test_static $A + (block $A (result (ref $A)) + (drop + (br_on_cast_static $A $A + (struct.new $A + (i32.const 200) + ) + ) + ) + (unreachable) + ) + ) + ) + ) ) |