diff --git a/src/ir/effects.h b/src/ir/effects.h index 25a108342bc..472c5a8af79 100644 --- a/src/ir/effects.h +++ b/src/ir/effects.h @@ -1044,10 +1044,8 @@ class EffectAnalyzer { } void visitRefGetDesc(RefGetDesc* curr) { trapOnNull(curr->ref); } void visitBrOn(BrOn* curr) { - if (trapOnNull(curr->desc)) { - return; - } parent.breakTargets.insert(curr->name); + trapOnNull(curr->desc); } void visitStructNew(StructNew* curr) { trapOnNull(curr->desc); } void visitStructGet(StructGet* curr) { diff --git a/test/lit/passes/monomorphize-desc.wast b/test/lit/passes/monomorphize-desc.wast new file mode 100644 index 00000000000..9523bc664a8 --- /dev/null +++ b/test/lit/passes/monomorphize-desc.wast @@ -0,0 +1,65 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. + +;; RUN: foreach %s %t wasm-opt --monomorphize -all -S -o - | filecheck %s + +(module + (rec + ;; CHECK: (rec + ;; CHECK-NEXT: (type $A (descriptor $B) (struct)) + (type $A (descriptor $B) (struct)) + ;; CHECK: (type $B (describes $A) (struct)) + (type $B (describes $A) (struct)) + ) + + ;; CHECK: (type $2 (func (param i32))) + + ;; CHECK: (type $3 (func (result anyref))) + + ;; CHECK: (type $4 (func (param nullref))) + + ;; CHECK: (func $target (type $2) (param $0 i32) + ;; CHECK-NEXT: (nop) + ;; CHECK-NEXT: ) + (func $target (param i32) + ) + + ;; CHECK: (func $test (type $3) (result anyref) + ;; CHECK-NEXT: (block $block (result (ref $A)) + ;; CHECK-NEXT: (call $target_2 + ;; CHECK-NEXT: (block ;; (replaces unreachable BrOn we can't emit) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $test (result anyref) + ;; We can monomorphize the call to $target, pushing the ref.is_null into + ;; $target_2. The parameter we send there is now nullref, so everything there + ;; gets optimized away. In this function, after refinalizing we end up with + ;; an unprintable br_on (we don't have defined types for the null inputs, and + ;; in fact the br_on is never taken). While doing so, we should not hit an + ;; internal error. + (block $block (result (ref $A)) + (call $target + (ref.is_null + (br_on_cast_desc_eq $block anyref (ref $A) + (ref.null none) + (ref.null none) + ) + ) + ) + (unreachable) + ) + ) +) + +;; CHECK: (func $target_2 (type $4) (param $0 nullref) +;; CHECK-NEXT: (nop) +;; CHECK-NEXT: )