summaryrefslogtreecommitdiff
path: root/test/lit/exec/i31.wast
blob: 807641d2440165284752b726ee95fa6c5f466407 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
;; NOTE: Assertions have been generated by update_lit_checks.py --output=fuzz-exec and should not be edited.

;; RUN: wasm-opt %s -all --fuzz-exec -q -o /dev/null 2>&1 | filecheck %s

(module
  ;; CHECK:      [fuzz-exec] calling null-local
  ;; CHECK-NEXT: [fuzz-exec] note result: null-local => 1
  (func $null-local (export "null-local") (result i32)
    (local $ref (ref null i31))
    (ref.is_null
      (local.get $ref)
    )
  )

  ;; CHECK:      [fuzz-exec] calling null-immediate
  ;; CHECK-NEXT: [fuzz-exec] note result: null-immediate => 1
  (func $null-immediate (export "null-immediate") (result i32)
    (ref.is_null
      (ref.null i31)
    )
  )

  ;; CHECK:      [fuzz-exec] calling non-null
  ;; CHECK-NEXT: [fuzz-exec] note result: non-null => 0
  (func $non-null (export "non-null") (result i32)
    (ref.is_null
      (ref.i31
        (i32.const 1234)
      )
    )
  )

  ;; CHECK:      [fuzz-exec] calling nn-u
  ;; CHECK-NEXT: [fuzz-exec] note result: nn-u => 2147483647
  (func $nn-u (export "nn-u") (result i32)
    (i31.get_u
      (ref.i31
        (i32.const 0xffffffff)
      )
    )
  )

  ;; CHECK:      [fuzz-exec] calling nn-s
  ;; CHECK-NEXT: [fuzz-exec] note result: nn-s => -1
  (func $nn-s (export "nn-s") (result i32)
    (i31.get_s
      (ref.i31
        (i32.const 0xffffffff)
      )
    )
  )

  ;; CHECK:      [fuzz-exec] calling zero-is-not-null
  ;; CHECK-NEXT: [fuzz-exec] note result: zero-is-not-null => 0
  (func $zero-is-not-null (export "zero-is-not-null") (result i32)
    (local $ref (ref null i31))
    (local.set $ref
      (ref.i31
        (i32.const 0)
      )
    )
    (i32.add ;; 0 + 0 is 0
      (ref.is_null
        (local.get $ref)
      )
      (i31.get_u ;; this should not trap on null
        (local.get $ref)
      )
    )
  )

  ;; CHECK:      [fuzz-exec] calling trap
  ;; CHECK-NEXT: [trap null ref]
  (func $trap (export "trap") (result i32)
    (i31.get_u
      (ref.null i31)
    )
  )

  ;; CHECK:      [fuzz-exec] calling return-i31
  ;; CHECK-NEXT: [fuzz-exec] note result: return-i31 => i31ref(42)
  (func $return-i31 (export "return-i31") (result i31ref)
    ;; An i31 should be logged out using its integer value, unlike a struct or
    ;; array which ends up as only "object".
    (ref.i31
      (i32.const 42)
    )
  )

  ;; CHECK:      [fuzz-exec] calling return-exted-i31
  ;; CHECK-NEXT: [fuzz-exec] note result: return-exted-i31 => i31ref(42)
  (func $return-exted-i31 (export "return-exted-i31") (result externref)
    ;; Even an externalized i31 is logged out using its integer value.
    (extern.convert_any
      (ref.i31
        (i32.const 42)
      )
    )
  )
)
;; CHECK:      [fuzz-exec] calling null-local
;; CHECK-NEXT: [fuzz-exec] note result: null-local => 1

;; CHECK:      [fuzz-exec] calling null-immediate
;; CHECK-NEXT: [fuzz-exec] note result: null-immediate => 1

;; CHECK:      [fuzz-exec] calling non-null
;; CHECK-NEXT: [fuzz-exec] note result: non-null => 0

;; CHECK:      [fuzz-exec] calling nn-u
;; CHECK-NEXT: [fuzz-exec] note result: nn-u => 2147483647

;; CHECK:      [fuzz-exec] calling nn-s
;; CHECK-NEXT: [fuzz-exec] note result: nn-s => -1

;; CHECK:      [fuzz-exec] calling zero-is-not-null
;; CHECK-NEXT: [fuzz-exec] note result: zero-is-not-null => 0

;; CHECK:      [fuzz-exec] calling trap
;; CHECK-NEXT: [trap null ref]

;; CHECK:      [fuzz-exec] calling return-i31
;; CHECK-NEXT: [fuzz-exec] note result: return-i31 => i31ref(42)

;; CHECK:      [fuzz-exec] calling return-exted-i31
;; CHECK-NEXT: [fuzz-exec] note result: return-exted-i31 => i31ref(42)
;; CHECK-NEXT: [fuzz-exec] comparing nn-s
;; CHECK-NEXT: [fuzz-exec] comparing nn-u
;; CHECK-NEXT: [fuzz-exec] comparing non-null
;; CHECK-NEXT: [fuzz-exec] comparing null-immediate
;; CHECK-NEXT: [fuzz-exec] comparing null-local
;; CHECK-NEXT: [fuzz-exec] comparing return-exted-i31
;; CHECK-NEXT: [fuzz-exec] comparing return-i31
;; CHECK-NEXT: [fuzz-exec] comparing trap
;; CHECK-NEXT: [fuzz-exec] comparing zero-is-not-null