summaryrefslogtreecommitdiff
path: root/test/lit/ctor-eval/partial-global.wat
diff options
context:
space:
mode:
Diffstat (limited to 'test/lit/ctor-eval/partial-global.wat')
-rw-r--r--test/lit/ctor-eval/partial-global.wat39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/lit/ctor-eval/partial-global.wat b/test/lit/ctor-eval/partial-global.wat
new file mode 100644
index 000000000..fdd196d02
--- /dev/null
+++ b/test/lit/ctor-eval/partial-global.wat
@@ -0,0 +1,39 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+;; RUN: wasm-ctor-eval %s --ctors=test --kept-exports=test --quiet -all -S -o - | filecheck %s
+
+(module
+ ;; CHECK: (type $none_=>_none (func))
+
+ ;; CHECK: (global $global (mut i32) (i32.const 0))
+ (global $global (mut i32) (i32.const 0))
+
+ (func $test (export "test")
+ ;; The nop can be evalled away, but not the loop. We should not apply any
+ ;; partial results from the loop - in particular, the global must remain at
+ ;; 0. That is, the global.set of 999 below must not be applied to the global.
+ ;;
+ ;; (It is true that in this simple module it would be ok to set 999 to the
+ ;; global, but if the global were exported for example then that would not
+ ;; be the case, nor would it be the case if the code did $global = $global + 1
+ ;; or such. That is, since the global.set is not evalled away, its effects
+ ;; must not be applied; we do both atomically or neither, so that the
+ ;; global.set's execution only happens once.)
+
+ (nop)
+ (loop
+ (global.set $global
+ (i32.const 999)
+ )
+ (unreachable)
+ )
+ )
+)
+
+;; CHECK: (export "test" (func $test_1))
+
+;; CHECK: (func $test_1 (type $none_=>_none)
+;; CHECK-NEXT: (global.set $global
+;; CHECK-NEXT: (i32.const 999)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (unreachable)
+;; CHECK-NEXT: )