summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/lit/passes/gufa-refs.wast261
1 files changed, 261 insertions, 0 deletions
diff --git a/test/lit/passes/gufa-refs.wast b/test/lit/passes/gufa-refs.wast
index 4be45e4ca..9a32c1acb 100644
--- a/test/lit/passes/gufa-refs.wast
+++ b/test/lit/passes/gufa-refs.wast
@@ -5622,6 +5622,267 @@
)
)
+;; Packed fields with signed gets.
+(module
+ ;; CHECK: (type $array (array (mut i8)))
+
+ ;; CHECK: (type $1 (func))
+
+ ;; CHECK: (type $struct (struct (field i16)))
+ (type $struct (struct (field i16)))
+
+ (type $array (array (mut i8)))
+
+ ;; CHECK: (func $test-struct (type $1)
+ ;; CHECK-NEXT: (local $x (ref $struct))
+ ;; CHECK-NEXT: (local.set $x
+ ;; CHECK-NEXT: (struct.new $struct
+ ;; CHECK-NEXT: (i32.const -1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (i32.const -1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (i32.const 65535)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $test-struct
+ (local $x (ref $struct))
+ (local.set $x
+ (struct.new $struct
+ (i32.const -1)
+ )
+ )
+ ;; This reads -1.
+ (drop
+ (struct.get_s $struct 0
+ (local.get $x)
+ )
+ )
+ ;; This reads 65535, as the other bits were truncated.
+ (drop
+ (struct.get_u $struct 0
+ (local.get $x)
+ )
+ )
+ )
+
+ ;; CHECK: (func $test-array (type $1)
+ ;; CHECK-NEXT: (local $x (ref $array))
+ ;; CHECK-NEXT: (local.set $x
+ ;; CHECK-NEXT: (array.new_fixed $array 1
+ ;; CHECK-NEXT: (i32.const -1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (block (result i32)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (array.get_s $array
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: (i32.const 0)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (i32.const -1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (block (result i32)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (array.get_u $array
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: (i32.const 0)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (i32.const 255)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $test-array
+ (local $x (ref $array))
+ (local.set $x
+ (array.new_fixed $array 1
+ (i32.const -1)
+ )
+ )
+ ;; This reads -1.
+ (drop
+ (array.get_s $array
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ ;; This reads 255, as the other bits were truncated.
+ (drop
+ (array.get_u $array
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ )
+)
+
+;; Packed fields with conflicting sets.
+(module
+
+ ;; CHECK: (type $struct (struct (field i16)))
+
+ ;; CHECK: (type $1 (func))
+
+ ;; CHECK: (import "a" "b" (global $import i32))
+ (import "a" "b" (global $import i32))
+
+ (type $struct (struct (field i16)))
+
+ ;; CHECK: (func $test-struct (type $1)
+ ;; CHECK-NEXT: (local $x (ref null $struct))
+ ;; CHECK-NEXT: (if
+ ;; CHECK-NEXT: (global.get $import)
+ ;; CHECK-NEXT: (then
+ ;; CHECK-NEXT: (local.set $x
+ ;; CHECK-NEXT: (struct.new $struct
+ ;; CHECK-NEXT: (i32.const -1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (else
+ ;; CHECK-NEXT: (local.set $x
+ ;; CHECK-NEXT: (struct.new $struct
+ ;; CHECK-NEXT: (i32.const 42)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (struct.get_s $struct 0
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (struct.get_u $struct 0
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $test-struct
+ (local $x (ref null $struct))
+ (if
+ (global.get $import)
+ (then
+ (local.set $x
+ (struct.new $struct
+ (i32.const -1)
+ )
+ )
+ )
+ (else
+ (local.set $x
+ (struct.new $struct
+ (i32.const 42)
+ )
+ )
+ )
+ )
+ ;; We cannot infer anything for these reads.
+ (drop
+ (struct.get_s $struct 0
+ (local.get $x)
+ )
+ )
+ (drop
+ (struct.get_u $struct 0
+ (local.get $x)
+ )
+ )
+ )
+)
+
+;; Packed fields with different sets that actually do not conflict.
+(module
+
+ ;; CHECK: (type $struct (struct (field i16)))
+
+ ;; CHECK: (type $1 (func))
+
+ ;; CHECK: (import "a" "b" (global $import i32))
+ (import "a" "b" (global $import i32))
+
+ (type $struct (struct (field i16)))
+
+ ;; CHECK: (func $test-struct (type $1)
+ ;; CHECK-NEXT: (local $x (ref null $struct))
+ ;; CHECK-NEXT: (if
+ ;; CHECK-NEXT: (global.get $import)
+ ;; CHECK-NEXT: (then
+ ;; CHECK-NEXT: (local.set $x
+ ;; CHECK-NEXT: (struct.new $struct
+ ;; CHECK-NEXT: (i32.const -1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (else
+ ;; CHECK-NEXT: (local.set $x
+ ;; CHECK-NEXT: (struct.new $struct
+ ;; CHECK-NEXT: (i32.const 65535)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (block (result i32)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (struct.get_s $struct 0
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (i32.const -1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (block (result i32)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (struct.get_u $struct 0
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (i32.const 65535)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $test-struct
+ (local $x (ref null $struct))
+ (if
+ (global.get $import)
+ (then
+ (local.set $x
+ (struct.new $struct
+ (i32.const -1)
+ )
+ )
+ )
+ (else
+ (local.set $x
+ (struct.new $struct
+ (i32.const 65535)
+ )
+ )
+ )
+ )
+ ;; We can infer here because -1 and 65535 are actually the same, after
+ ;; truncation.
+ (drop
+ (struct.get_s $struct 0
+ (local.get $x)
+ )
+ )
+ (drop
+ (struct.get_u $struct 0
+ (local.get $x)
+ )
+ )
+ )
+)
+
;; Test that we do not error on array.init of a bottom type.
(module
(type $"[mut:i32]" (array (mut i32)))