Skip to content

Commit

Permalink
Fix segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed May 1, 2024
1 parent ab4631f commit 0480d66
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/compiler.pr
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,17 @@ def convert_ref_to_ref(tpe: &typechecking::Type, value: Value, loc: &Value, stat
// Convert weak ref to strong reference
// Need to check the ref count and return a null reference if its 0
if is_weak_ref(value.tpe) and is_ref(tpe) {
let ref_value = state.ptr_to_int(extract1_ret, 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 = state.load(ref_meta, extract1_ret, loc)
let refcount = state.extract_value(builtins::int64_, meta, [0], loc)
let iszero = state.icmp(CompareInt::sle, refcount,
Expand All @@ -1439,6 +1450,7 @@ def convert_ref_to_ref(tpe: &typechecking::Type, value: Value, loc: &Value, stat
push_insn(br, state)
let if_true = make_label(state)
push_label(if_true, state)
br1.value.br.if_true = if_true
br.value.br.if_true = if_true

// Null reference
Expand Down

0 comments on commit 0480d66

Please sign in to comment.