Skip to content

Commit 7a6d962

Browse files
authored
Precompute: Check defaultability, not nullability (#6052)
Followup to #6048, we did not handle nondefaultable tuples because of this.
1 parent ea6bcd0 commit 7a6d962

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

src/passes/Precompute.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ struct Precompute
441441
if (set == nullptr) {
442442
if (getFunction()->isVar(get->index)) {
443443
auto localType = getFunction()->getLocalType(get->index);
444-
if (localType.isNonNullable()) {
445-
// This is a non-nullable local that seems to read the default
444+
if (!localType.isDefaultable()) {
445+
// This is a nondefaultable local that seems to read the default
446446
// value at the function entry. This is either an internal error
447447
// or a case of unreachable code; the latter is possible as
448448
// LocalGraph is not precise in unreachable code.

test/lit/passes/precompute-gc.wast

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@
229229
(struct.get $struct 0 (local.get $x))
230230
)
231231
)
232-
;; CHECK: (func $ref-comparisons (type $10) (param $x (ref null $struct)) (param $y (ref null $struct))
232+
;; CHECK: (func $ref-comparisons (type $11) (param $x (ref null $struct)) (param $y (ref null $struct))
233233
;; CHECK-NEXT: (local $z (ref null $struct))
234234
;; CHECK-NEXT: (local $w (ref null $struct))
235235
;; CHECK-NEXT: (call $log
@@ -407,7 +407,7 @@
407407
(local.get $tempresult)
408408
)
409409

410-
;; CHECK: (func $propagate-different-params (type $11) (param $input1 (ref $empty)) (param $input2 (ref $empty)) (result i32)
410+
;; CHECK: (func $propagate-different-params (type $12) (param $input1 (ref $empty)) (param $input2 (ref $empty)) (result i32)
411411
;; CHECK-NEXT: (local $tempresult i32)
412412
;; CHECK-NEXT: (local.set $tempresult
413413
;; CHECK-NEXT: (ref.eq
@@ -723,7 +723,7 @@
723723
)
724724
)
725725

726-
;; CHECK: (func $helper (type $12) (param $0 i32) (result i32)
726+
;; CHECK: (func $helper (type $13) (param $0 i32) (result i32)
727727
;; CHECK-NEXT: (unreachable)
728728
;; CHECK-NEXT: )
729729
(func $helper (param i32) (result i32)
@@ -801,14 +801,14 @@
801801
)
802802
)
803803

804-
;; CHECK: (func $receive-f64 (type $13) (param $0 f64)
804+
;; CHECK: (func $receive-f64 (type $14) (param $0 f64)
805805
;; CHECK-NEXT: (unreachable)
806806
;; CHECK-NEXT: )
807807
(func $receive-f64 (param f64)
808808
(unreachable)
809809
)
810810

811-
;; CHECK: (func $odd-cast-and-get-non-null (type $14) (param $temp (ref $func-return-i32))
811+
;; CHECK: (func $odd-cast-and-get-non-null (type $15) (param $temp (ref $func-return-i32))
812812
;; CHECK-NEXT: (local.set $temp
813813
;; CHECK-NEXT: (ref.cast (ref nofunc)
814814
;; CHECK-NEXT: (ref.func $receive-f64)
@@ -857,7 +857,7 @@
857857
)
858858
)
859859

860-
;; CHECK: (func $br_on_cast-on-creation (type $15) (result (ref $empty))
860+
;; CHECK: (func $br_on_cast-on-creation (type $16) (result (ref $empty))
861861
;; CHECK-NEXT: (block $label (result (ref $empty))
862862
;; CHECK-NEXT: (drop
863863
;; CHECK-NEXT: (br_on_cast $label (ref $empty) (ref $empty)
@@ -952,7 +952,7 @@
952952
)
953953
)
954954

955-
;; CHECK: (func $remove-set (type $16) (result (ref func))
955+
;; CHECK: (func $remove-set (type $17) (result (ref func))
956956
;; CHECK-NEXT: (local $nn funcref)
957957
;; CHECK-NEXT: (local $i i32)
958958
;; CHECK-NEXT: (loop $loop
@@ -995,7 +995,7 @@
995995
)
996996
)
997997

998-
;; CHECK: (func $strings (type $17) (param $param (ref string))
998+
;; CHECK: (func $strings (type $18) (param $param (ref string))
999999
;; CHECK-NEXT: (local $s (ref string))
10001000
;; CHECK-NEXT: (local.set $s
10011001
;; CHECK-NEXT: (string.const "hello, world")
@@ -1141,4 +1141,29 @@
11411141
)
11421142
)
11431143
)
1144+
1145+
;; CHECK: (func $get-nonnullable-in-unreachable-tuple (type $19) (result anyref i32)
1146+
;; CHECK-NEXT: (local $x ((ref any) i32))
1147+
;; CHECK-NEXT: (local.tee $x
1148+
;; CHECK-NEXT: (unreachable)
1149+
;; CHECK-NEXT: )
1150+
;; CHECK-NEXT: (if
1151+
;; CHECK-NEXT: (i32.const 1)
1152+
;; CHECK-NEXT: (unreachable)
1153+
;; CHECK-NEXT: )
1154+
;; CHECK-NEXT: (local.get $x)
1155+
;; CHECK-NEXT: )
1156+
(func $get-nonnullable-in-unreachable-tuple (result anyref i32)
1157+
;; As $get-nonnullable-in-unreachable but the local is a tuple (so we need to
1158+
;; check isDefaultable, and not just isNullable).
1159+
(local $x ((ref any) i32))
1160+
(local.set $x
1161+
(unreachable)
1162+
)
1163+
(if
1164+
(i32.const 1)
1165+
(unreachable)
1166+
)
1167+
(local.get $x)
1168+
)
11441169
)

0 commit comments

Comments
 (0)