Skip to content

Commit 647a2e1

Browse files
authored
Propagate exactness when combining GUFA possible contents (#7537)
The logic for joining nullability into a PossibleContents cone value did not previously preserve the exactness of the type in the cone value, causing assertion failures.
1 parent 1807705 commit 647a2e1

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/ir/possible-contents.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ PossibleContents PossibleContents::combine(const PossibleContents& a,
102102
// just add in nullability. For example, a literal of type T and a null
103103
// becomes an exact type of T that allows nulls, and so forth.
104104
auto mixInNull = [](ConeType cone) {
105-
cone.type = Type(cone.type.getHeapType(), Nullable);
105+
cone.type = cone.type.with(Nullable);
106106
return cone;
107107
};
108108
if (!a.isNull()) {

test/lit/passes/gufa-cast-all-exact.wast

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,32 @@
109109
)
110110
)
111111
)
112+
113+
(module
114+
;; CHECK: (type $foo (struct (field i32)))
115+
;; NO_CD: (type $foo (struct (field i32)))
116+
(type $foo (struct (field i32)))
117+
118+
;; CHECK: (import "" "" (global $exact (ref (exact $foo))))
119+
;; NO_CD: (import "" "" (global $exact (ref (exact $foo))))
120+
(import "" "" (global $exact (ref (exact $foo))))
121+
122+
;; CHECK: (func $get (type $1) (result i32)
123+
;; CHECK-NEXT: (unreachable)
124+
;; CHECK-NEXT: )
125+
;; NO_CD: (func $get (type $1) (result i32)
126+
;; NO_CD-NEXT: (unreachable)
127+
;; NO_CD-NEXT: )
128+
(func $get (result i32)
129+
;; Regression test for a bug where exactness was not preserved when combining
130+
;; nullness into cone types, resulting in a later assertion failure on the
131+
;; StructGet.
132+
(struct.get $foo 0
133+
(select (result (ref null (exact $foo)))
134+
(global.get $exact)
135+
(ref.null none)
136+
(i32.const 0)
137+
)
138+
)
139+
)
140+
)

0 commit comments

Comments
 (0)