summaryrefslogtreecommitdiff
path: root/test/passes/simplify-locals.wast
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-10-11 10:13:06 -0700
committerGitHub <noreply@github.com>2017-10-11 10:13:06 -0700
commitf0d858b6c2793f7bae00e4c5dc2d0f38fc1e30f8 (patch)
treec2b59ad237e7eddc2eeee3c5f42aa82447012eaa /test/passes/simplify-locals.wast
parent69408e62ee1909c09a9a1a87616b3d0f6a8329e5 (diff)
downloadbinaryen-f0d858b6c2793f7bae00e4c5dc2d0f38fc1e30f8.tar.gz
binaryen-f0d858b6c2793f7bae00e4c5dc2d0f38fc1e30f8.tar.bz2
binaryen-f0d858b6c2793f7bae00e4c5dc2d0f38fc1e30f8.zip
fix simplify-locals bug where we create a br_if value, which is dangerous if we are moving code out of the br_if's condition - the value executes before (#1213)
Diffstat (limited to 'test/passes/simplify-locals.wast')
-rw-r--r--test/passes/simplify-locals.wast47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/passes/simplify-locals.wast b/test/passes/simplify-locals.wast
index 10fcf1277..842e2b5af 100644
--- a/test/passes/simplify-locals.wast
+++ b/test/passes/simplify-locals.wast
@@ -940,4 +940,51 @@
(drop (i32.atomic.load (i32.const 1028)))
(drop (get_local $x))
)
+ (func $br-value-reordering (result i32)
+ (local $temp i32)
+ (block $outside
+ (loop $loop ;; we should exit this loop, hit the unreachable outside
+ ;; loop logic
+ (br_if $outside ;; we should not create a block value that adds a value to a br, if the value&condition of the br cannot be reordered,
+ ;; as the value comes first
+ (block (result i32)
+ (br_if $loop
+ (get_local $temp) ;; false, don't loop
+ )
+ (unreachable) ;; the end
+ (set_local $temp
+ (i32.const -1)
+ )
+ (i32.const 0)
+ )
+ )
+ )
+ (set_local $temp
+ (i32.const -1)
+ )
+ )
+ (unreachable)
+ )
+ (func $br-value-reordering-safe (result i32)
+ (local $temp i32)
+ (block $outside
+ (loop $loop ;; we should exit this loop, hit the unreachable outside
+ ;; loop logic
+ (drop (get_local $temp)) ;; different from above - add a use here
+ (br_if $outside ;; we should not create a block value that adds a value to a br, if the value&condition of the br cannot be reordered,
+ ;; as the value comes first
+ (block (result i32)
+ (set_local $temp ;; the use *is* in the condition, but it's ok, no conflicts
+ (i32.const -1)
+ )
+ (i32.const 0)
+ )
+ )
+ )
+ (set_local $temp
+ (i32.const -1)
+ )
+ )
+ (unreachable)
+ )
)