Skip to content

Commit 3da0ceb

Browse files
authored
[GC] Add missing ReFinalize to GlobalStructInference (#7620)
1 parent 1625f5b commit 3da0ceb

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/passes/GlobalStructInference.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,13 @@ struct GlobalStructInference : public Pass {
447447
ret = get;
448448
}
449449

450+
// If the type is more refined, we must refinalize. For example, we
451+
// might have a struct.get that normally returns anyref, and know that
452+
// field contains null, so we return nullref.
453+
if (ret->type != curr->type) {
454+
refinalize = true;
455+
}
456+
450457
// This value replaces the struct.get, so it should have the same
451458
// source location.
452459
debuginfo::copyOriginalToReplacement(curr, ret, getFunction());

test/lit/passes/gsi.wast

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,3 +2241,41 @@
22412241
)
22422242
)
22432243
)
2244+
2245+
;; The field has type nullable $A, but we can infer it contains null (as both
2246+
;; globals do). This leads to refining the types of the parents.
2247+
(module
2248+
;; CHECK: (type $A (struct (field (ref null $A))))
2249+
(type $A (struct (field (ref null $A))))
2250+
2251+
;; CHECK: (type $1 (func (param (ref $A)) (result (ref $A))))
2252+
2253+
;; CHECK: (global $global$1 (ref (exact $A)) (struct.new_default $A))
2254+
(global $global$1 (ref (exact $A)) (struct.new_default $A))
2255+
2256+
;; CHECK: (global $global$2 (ref (exact $A)) (struct.new_default $A))
2257+
(global $global$2 (ref (exact $A)) (struct.new_default $A))
2258+
2259+
;; CHECK: (func $func (type $1) (param $A (ref $A)) (result (ref $A))
2260+
;; CHECK-NEXT: (ref.as_non_null
2261+
;; CHECK-NEXT: (block (result nullref)
2262+
;; CHECK-NEXT: (drop
2263+
;; CHECK-NEXT: (ref.as_non_null
2264+
;; CHECK-NEXT: (local.get $A)
2265+
;; CHECK-NEXT: )
2266+
;; CHECK-NEXT: )
2267+
;; CHECK-NEXT: (ref.null none)
2268+
;; CHECK-NEXT: )
2269+
;; CHECK-NEXT: )
2270+
;; CHECK-NEXT: )
2271+
(func $func (param $A (ref $A)) (result (ref $A))
2272+
;; The block's result should refine.
2273+
(block (result (ref $A))
2274+
(ref.as_non_null
2275+
(struct.get $A 0
2276+
(local.get $A)
2277+
)
2278+
)
2279+
)
2280+
)
2281+
)

0 commit comments

Comments
 (0)