From 715d3305fb288ea66eb57f171f7ea756b4399833 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 5 Jul 2016 10:12:12 -0700 Subject: [PATCH 1/3] Add tests for conflicting-but-ultimately-dropped values. --- ml-proto/test/br.wast | 23 +++++++++++++++++++++++ ml-proto/test/br_if.wast | 22 ++++++++++++++++++++++ ml-proto/test/br_table.wast | 22 ++++++++++++++++++++++ ml-proto/test/typecheck.wast | 10 ++++++++++ 4 files changed, 77 insertions(+) diff --git a/ml-proto/test/br.wast b/ml-proto/test/br.wast index ce34922420..b653bfea15 100644 --- a/ml-proto/test/br.wast +++ b/ml-proto/test/br.wast @@ -417,3 +417,26 @@ (module (func $large-label (br 0x100000001))) "unknown label" ) + +;; Test that the value operand of br_if matches the result type of the block +;; it branches to, even if the result of the block is dropped. +(assert_invalid + (module + (func $bar (param $x i32) (param $y f32) + (drop + (block $green + (br $green (get_local $x)) + (get_local $y))))) + "type mismatch") + +;; Test that the value operand of br matches the result type of other +;; branches to the same block, even if the result of the block is dropped. +(assert_invalid + (module + (func $bar (param $x i32) (param $y f32) + (drop + (block $green + (br $green (get_local $x)) + (br $green (get_local $y)) + (get_local $x))))) + "type mismatch") diff --git a/ml-proto/test/br_if.wast b/ml-proto/test/br_if.wast index d0a79b5d14..fa72482c9f 100644 --- a/ml-proto/test/br_if.wast +++ b/ml-proto/test/br_if.wast @@ -306,3 +306,25 @@ "unknown label" ) +;; Test that the value operand of br_if matches the result type of the block +;; it branches to, even if the result of the block is dropped. +(assert_invalid + (module + (func $bar (param $x i32) (param $y f32) (param $cond i32) + (drop + (block $green + (br_if $green (get_local $x) (get_local $cond)) + (get_local $y))))) + "type mismatch") + +;; Test that the value operand of br_if matches the result type of other +;; branches to the same block, even if the result of the block is dropped. +(assert_invalid + (module + (func $bar (param $x i32) (param $y f32) (param $cond i32) + (drop + (block $green + (br_if $green (get_local $x) (get_local $cond)) + (br_if $green (get_local $y) (get_local $cond)) + (get_local $x))))) + "type mismatch") diff --git a/ml-proto/test/br_table.wast b/ml-proto/test/br_table.wast index aab0a61c70..e49d41f513 100644 --- a/ml-proto/test/br_table.wast +++ b/ml-proto/test/br_table.wast @@ -1385,3 +1385,25 @@ "unknown label" ) +;; Test that the value operand of br_if matches the result type of the block +;; it branches to, even if the result of the block is dropped. +(assert_invalid + (module + (func $bar (param $x i32) (param $y f32) (param $index i32) + (drop + (block $green + (br_table $green $green (get_local $x) (get_local $index)) + (get_local $y))))) + "type mismatch") + +;; Test that the value operand of br_table matches the result type of other +;; branches to the same block, even if the result of the block is dropped. +(assert_invalid + (module + (func $bar (param $x i32) (param $y f32) (param $index i32) + (drop + (block $green + (br_table $green $green (get_local $x) (get_local $index)) + (br_table $green $green (get_local $y) (get_local $index)) + (get_local $x))))) + "type mismatch") diff --git a/ml-proto/test/typecheck.wast b/ml-proto/test/typecheck.wast index 8522f754f1..c84f7236ea 100644 --- a/ml-proto/test/typecheck.wast +++ b/ml-proto/test/typecheck.wast @@ -4,6 +4,16 @@ ;; if condition (assert_invalid (module (func (if (f32.const 0) (nop) (nop)))) "type mismatch") +;; if arms +(assert_invalid + (module + (func $foo (param $x i32) (param $y f32) (param $cond f32) + (drop + (if (get_local $cond) + (get_local $y) + (get_local $x))))) + "type mismatch") + ;; br_if condition (assert_invalid (module (func (block (br_if 0 (f32.const 0))))) "type mismatch") From e7ca904016836c79a7b4ecea96088cf01ca43618 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 5 Jul 2016 10:25:42 -0700 Subject: [PATCH 2/3] Fix copypasta in comments. --- ml-proto/test/br.wast | 2 +- ml-proto/test/br_table.wast | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ml-proto/test/br.wast b/ml-proto/test/br.wast index b653bfea15..d439ee1ce6 100644 --- a/ml-proto/test/br.wast +++ b/ml-proto/test/br.wast @@ -418,7 +418,7 @@ "unknown label" ) -;; Test that the value operand of br_if matches the result type of the block +;; Test that the value operand of br matches the result type of the block ;; it branches to, even if the result of the block is dropped. (assert_invalid (module diff --git a/ml-proto/test/br_table.wast b/ml-proto/test/br_table.wast index e49d41f513..e81592bd3d 100644 --- a/ml-proto/test/br_table.wast +++ b/ml-proto/test/br_table.wast @@ -1385,7 +1385,7 @@ "unknown label" ) -;; Test that the value operand of br_if matches the result type of the block +;; Test that the value operand of br_table matches the result type of the block ;; it branches to, even if the result of the block is dropped. (assert_invalid (module From d503f1710139dc0a6d0406bb1f5847268f236eed Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 5 Jul 2016 11:19:09 -0700 Subject: [PATCH 3/3] Fix a thinko in a test. Fix the type of the condition of an if, so that the test tests what it's supposed to test. --- ml-proto/test/typecheck.wast | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ml-proto/test/typecheck.wast b/ml-proto/test/typecheck.wast index c84f7236ea..d251e94dd1 100644 --- a/ml-proto/test/typecheck.wast +++ b/ml-proto/test/typecheck.wast @@ -7,7 +7,7 @@ ;; if arms (assert_invalid (module - (func $foo (param $x i32) (param $y f32) (param $cond f32) + (func $foo (param $x i32) (param $y f32) (param $cond i32) (drop (if (get_local $cond) (get_local $y)