Skip to content

Commit 5d894fc

Browse files
authored
Fix assertion failure in type-refining-gufa (#7612)
`filterPackedDataReads` had an assertion that the read field existed, but it was possible for this to not be the case when the reference being read from was null. Avoid the assertion failure by checking for this case and filtering the read results to `none` because a read from null will never return.
1 parent f11598b commit 5d894fc

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/ir/possible-contents.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,6 +2825,12 @@ void Flower::filterPackedDataReads(PossibleContents& contents,
28252825
return;
28262826
}
28272827

2828+
// If there is no struct or array to read, no value will ever be returned.
2829+
if (ref->type.isNull()) {
2830+
contents = PossibleContents::none();
2831+
return;
2832+
}
2833+
28282834
// We are reading data here, so the reference must be a valid struct or
28292835
// array, otherwise we would never have gotten here.
28302836
assert(ref->type.isRef());

test/lit/passes/type-refining-gufa.wast

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,54 @@
425425
(func $func (type $func)
426426
)
427427
)
428+
429+
;; Regression test for an assertion failure on packed data reads from null
430+
;; references.
431+
(module
432+
(type $i8 (struct (field i8)))
433+
434+
;; NRML: (type $0 (func (param (ref none)) (result i32)))
435+
436+
;; NRML: (table $0 1 funcref)
437+
;; GUFA: (type $0 (func (param (ref none)) (result i32)))
438+
439+
;; GUFA: (table $0 1 funcref)
440+
;; O3O3: (type $0 (func (param (ref none)) (result i32)))
441+
442+
;; O3O3: (table $0 1 funcref)
443+
(table $0 1 funcref)
444+
;; NRML: (elem $0 (i32.const 0) $test)
445+
;; GUFA: (elem $0 (i32.const 0) $test)
446+
;; O3O3: (elem $0 (i32.const 0) $test)
447+
(elem $0 (i32.const 0) $test)
448+
449+
;; NRML: (export "table" (table $0))
450+
;; GUFA: (export "table" (table $0))
451+
;; O3O3: (export "table" (table $0))
452+
(export "table" (table $0))
453+
454+
;; NRML: (func $test (type $0) (param $i8 (ref none)) (result i32)
455+
;; NRML-NEXT: (block ;; (replaces unreachable StructGet we can't emit)
456+
;; NRML-NEXT: (drop
457+
;; NRML-NEXT: (local.get $i8)
458+
;; NRML-NEXT: )
459+
;; NRML-NEXT: (unreachable)
460+
;; NRML-NEXT: )
461+
;; NRML-NEXT: )
462+
;; GUFA: (func $test (type $0) (param $i8 (ref none)) (result i32)
463+
;; GUFA-NEXT: (block ;; (replaces unreachable StructGet we can't emit)
464+
;; GUFA-NEXT: (drop
465+
;; GUFA-NEXT: (local.get $i8)
466+
;; GUFA-NEXT: )
467+
;; GUFA-NEXT: (unreachable)
468+
;; GUFA-NEXT: )
469+
;; GUFA-NEXT: )
470+
;; O3O3: (func $test (type $0) (param $0 (ref none)) (result i32)
471+
;; O3O3-NEXT: (unreachable)
472+
;; O3O3-NEXT: )
473+
(func $test (param $i8 (ref none)) (result i32)
474+
(struct.get_s $i8 0
475+
(local.get $i8)
476+
)
477+
)
478+
)

0 commit comments

Comments
 (0)