blob: 31f787e3dce1dc840222df5efb834502d4898544 [file]
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: foreach %s %t wasm-ctor-eval --ctors=test --kept-exports=test --quiet -all -S -o - | filecheck %s
;; This code does the following:
;;
;; * start writes global2, and traps if global1 is set.
;; * test sets global1.
;;
;; We must eval away the start function when we eval away the other. That is,
;; there should be no start function afterwards. Otherwise, if it remains as the
;; start, it will trap when it reads the modified global.
;;
;; While doing so we must apply the changes of the start function, to global2.
;; So both globals end up modified.
(module
;; CHECK: (type $0 (func (result i32)))
;; CHECK: (type $1 (func))
;; CHECK: (global $global1 (mut i32) (i32.const 1337))
(global $global1 (mut i32) (i32.const 0))
;; CHECK: (global $global2 (mut i32) (i32.const 42))
(global $global2 (mut i32) (i32.const 0))
(start $start)
(func $start
(global.set $global2
(i32.const 42)
)
(if
(global.get $global1)
(then
(unreachable)
)
)
)
(func $test (export "test")
(global.set $global1
(i32.const 1337)
)
)
;; CHECK: (export "test" (func $test_3))
;; CHECK: (export "keepalive" (func $keepalive))
;; CHECK: (func $keepalive (type $0) (result i32)
;; CHECK-NEXT: (i32.add
;; CHECK-NEXT: (global.get $global1)
;; CHECK-NEXT: (global.get $global2)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $keepalive (export "keepalive") (result i32)
;; Keep the globals alive to show changes.
(i32.add
(global.get $global1)
(global.get $global2)
)
)
)
;; CHECK: (func $test_3 (type $1)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )