diff --git a/src/compiler.pr b/src/compiler.pr index 4cb2aa3..ec3ff0b 100644 --- a/src/compiler.pr +++ b/src/compiler.pr @@ -1489,6 +1489,18 @@ def convert_ref_to_ref(tpe: &typechecking::Type, value: Value, loc: &Value, stat def convert_ref_to_ptr(tpe: &typechecking::Type, value: Value, loc: &Value, state: &State) -> Value { if is_weak_ref(value.tpe) { let meta = state.extract_value(pointer(ref_meta), value, [0], loc) + + let ref_value = state.ptr_to_int(meta, loc) + let isnull = state.icmp(CompareInt::eq, ref_value, + [ kind = ValueKind::INT, tpe = builtins::int64_, i = 0 ] !Value, loc) + + let br1 = make_insn_dbg(InsnKind::BR, loc) + br1.value.br = [ cond = isnull ] !InsnBr + push_insn(br1, state) + let nonnull = make_label(state) + push_label(nonnull, state) + br1.value.br.if_false = nonnull + let meta_val = state.load(ref_meta, meta, loc) let cnt = state.extract_value(builtins::int64_, meta_val, [0], loc) let iszero = state.icmp(CompareInt::sle, cnt, [ kind = ValueKind::INT, tpe = builtins::int64_, i = 0 ] !Value) @@ -1500,6 +1512,7 @@ def convert_ref_to_ptr(tpe: &typechecking::Type, value: Value, loc: &Value, stat let if_true = make_label(state) push_label(if_true, state) br.value.br.if_true = if_true + br1.value.br.if_true = if_true // Null pointer state.store(res, [ kind = ValueKind::ZEROINITIALIZER, tpe = pointer(tpe.tpe) ] !Value)