Skip to content

Commit 0ac8945

Browse files
committed
JIT: Fix missing untag of BSBinaryReg in do_get_tail
BSBinaryReg holds a tagged binary term (from match state element 1). In do_get_tail, it was used directly as a base pointer in get_array_element, causing ldr to use an address offset by the tag bits (TERM_PRIMARY_BOXED = 0x02). Signed-off-by: Paul Guyot <pguyot@kallisys.net>
1 parent c805acc commit 0ac8945

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

libs/jit/src/jit.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3134,7 +3134,10 @@ do_get_tail(
31343134
) ->
31353135
MSt1 = cond_raise_badarg({BSOffsetReg, '&', 2#111, '!=', 0}, MMod, MSt0),
31363136
{MSt2, BSOffseBytesReg} = MMod:shift_right(MSt1, BSOffsetReg, 3),
3137-
{MSt3, TailBytesReg0} = MMod:get_array_element(MSt2, BSBinaryReg, 1),
3137+
% BSBinaryReg is a tagged binary term from the match state;
3138+
% untag it before using as a pointer for get_array_element
3139+
{MSt2b, BSBinaryPtrReg} = MMod:and_(MSt2, BSBinaryReg, ?TERM_PRIMARY_CLEAR_MASK),
3140+
{MSt3, TailBytesReg0} = MMod:get_array_element(MSt2b, {free, BSBinaryPtrReg}, 1),
31383141
MSt4 = MMod:sub(MSt3, TailBytesReg0, BSOffseBytesReg),
31393142
{MSt5, HeapSizeReg} = MMod:call_primitive(MSt4, ?PRIM_TERM_SUB_BINARY_HEAP_SIZE, [
31403143
BSBinaryReg, {free, TailBytesReg0}

0 commit comments

Comments
 (0)