From ad603301ecce41274c50b761d80b841c08020cd7 Mon Sep 17 00:00:00 2001 From: Paul Guyot Date: Sun, 7 Sep 2025 21:23:05 +0200 Subject: [PATCH] opcodesswitch: fix OP_BS_CREATE_BIN that can have an allocator list Signed-off-by: Paul Guyot --- src/libAtomVM/opcodesswitch.h | 2 +- tests/erlang_tests/test_op_bs_create_bin.erl | 15 ++++++++++++++- tests/erlang_tests/test_op_bs_create_bin_asm.S | 14 ++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/libAtomVM/opcodesswitch.h b/src/libAtomVM/opcodesswitch.h index a6654378a..c941b3f2d 100644 --- a/src/libAtomVM/opcodesswitch.h +++ b/src/libAtomVM/opcodesswitch.h @@ -6576,7 +6576,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) uint32_t fail; DECODE_LABEL(fail, pc); uint32_t alloc; - DECODE_LITERAL(alloc, pc); + DECODE_ALLOCATOR_LIST(alloc, pc); uint32_t live; DECODE_LITERAL(live, pc); uint32_t unit; diff --git a/tests/erlang_tests/test_op_bs_create_bin.erl b/tests/erlang_tests/test_op_bs_create_bin.erl index d8335aae8..0d8610af3 100644 --- a/tests/erlang_tests/test_op_bs_create_bin.erl +++ b/tests/erlang_tests/test_op_bs_create_bin.erl @@ -38,7 +38,8 @@ start() -> ok = test_bs_create_bin_utf16(), ok = test_bs_create_bin_utf32(), ok = test_bs_create_bin_integer(), - ok = test_bs_create_bin_binary(); + ok = test_bs_create_bin_binary(), + ok = test_bs_create_bin_alloc_list(); true -> ok end, @@ -266,3 +267,15 @@ test_bs_create_bin_binary() -> error:badarg -> unexpected end, ok. + +test_bs_create_bin_alloc_list() -> + %% Test that bs_create_bin with allocator list works correctly + %% Expected result: <<0,0,0,42>> (42 as 32-bit big-endian integer) + Expected = <<0, 0, 0, 42>>, + Result = test_op_bs_create_bin_asm:bs_create_bin_alloc_list(42), + case Result of + Expected -> + ok; + _ -> + error({unexpected_result, Result, expected, Expected}) + end. diff --git a/tests/erlang_tests/test_op_bs_create_bin_asm.S b/tests/erlang_tests/test_op_bs_create_bin_asm.S index 8d1a8beda..4349c902d 100644 --- a/tests/erlang_tests/test_op_bs_create_bin_asm.S +++ b/tests/erlang_tests/test_op_bs_create_bin_asm.S @@ -31,12 +31,13 @@ {bs_create_bin_integer_no_fail, 3}, {bs_create_bin_integer_fail, 3}, {bs_create_bin_binary_no_fail, 3}, - {bs_create_bin_binary_fail, 3} + {bs_create_bin_binary_fail, 3}, + {bs_create_bin_alloc_list, 1} ]}. {attributes, []}. -{labels, 26}. +{labels, 28}. {function, bs_create_bin_utf8_no_fail, 3, 2}. {label, 1}. @@ -122,3 +123,12 @@ return. {label, 26}. {move, {atom, fail}, {x, 0}}. return. + +{function, bs_create_bin_alloc_list, 1, 28}. +{label, 27}. +{func_info, {atom, test_op_bs_create_bin_asm}, {atom, bs_create_bin_alloc_list}, 1}. +{label, 28}. +%% Test bs_create_bin with allocator list instead of simple literal +{bs_create_bin, {f, 0}, {alloc, [{words, 2}, {floats, 1}, {funs, 1}]}, 1, 1, {x, 0}, + {list, [{atom, integer}, 1, 1, nil, {x, 0}, {integer, 32}]}}. +return.