Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_function/3 opcode doesn't handle arity as a term #1382

Open
jakub-gonet opened this issue Dec 1, 2024 · 0 comments
Open

is_function/3 opcode doesn't handle arity as a term #1382

jakub-gonet opened this issue Dec 1, 2024 · 0 comments

Comments

@jakub-gonet
Copy link
Contributor

I will try to find minimal repro (or stacktraces/opcodes sequence) in few days but when working on porting Erlang to WASM I noticed that OP_IS_FUNCTION2 sometimes crashed.

After decoding it as a term, the crash disappeared:

@ -5252,37 +5251,41 @@ wait_timeout_trap_handler:
                   DECODE_LABEL(label, pc)
                   term arg1;
                   DECODE_COMPACT_TERM(arg1, pc)
-                  unsigned int arity;
-                  DECODE_INTEGER(arity, pc)
+                  term arity_term;
+                  DECODE_COMPACT_TERM(arity_term, pc)

                   #ifdef IMPL_EXECUTE_LOOP
-                      if (term_is_function(arg1)) {
-                          const term *boxed_value = term_to_const_term_ptr(arg1);
+                      if (term_is_function(arg1)) {
+                          const uint32_t arity = term_to_int(arity_term);
+                          const term *boxed_value = term_to_const_term_ptr(arg1);

Not sure if AVM does some post-processing for BEAM bytecode when compiling to .avm or something else is in play.

BEAM book suggests that the opcode should have term/register (depending on %hot/%cold modifiers) type in emulator mode but literal in JIT

@jakub-gonet jakub-gonet changed the title is_function/3 opcode sometimes is a term, crashing VM is_function/3 opcode doesn't handle arity as a term Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant