← index #15670Issue #17547
Related · medium · value 2.055
QUERY · ISSUE

Binary operations on undefined variables crash the native emitter.

openby agattiopened 2024-08-16updated 2024-12-30
bug

Port, board and/or hardware

unix

MicroPython version

MicroPython v1.24.0-preview.206.ge9814e987.dirty on 2024-08-16; linux [GCC 14.2.1] version

Reproduction

Run the following code:

@micropython.native
def f():
    a += 0  # Or anything else, really
f()

Expected behaviour

A NameError exception should be raised. (CPython raises NameError: name 'a' is not defined)

Observed behaviour

This is the backtrace of the crash when running the interpreter under GDB:

Program received signal SIGSEGV, Segmentation fault.
mp_obj_get_type (o_in=o_in@entry=0x0) at ../../py/obj.c:61
61              return o->type;
(gdb) bt
#0  mp_obj_get_type (o_in=o_in@entry=0x0) at ../../py/obj.c:61
#1  0x0000555555591333 in mp_binary_op (op=MP_BINARY_OP_INPLACE_ADD, lhs=0x0, rhs=0x1) at ../../py/runtime.c:630
#2  0x00007ffff7fc0053 in ?? ()
#3  0x00007ffff7a06440 in ?? ()
#4  0x00007ffff7fc006d in ?? ()
#5  0x00007fffffff9610 in ?? ()
#6  0x0000000000000003 in ?? ()
#7  0x00007fffffff9760 in ?? ()
#8  0x0000000000000000 in ?? ()

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

mpy-cross: Assertion failed when compiling tests/basics/exception_chain.py.

openby agattiopened 2025-06-22updated 2025-12-23
bug

Port, board and/or hardware

Unix on Linux/amd64

MicroPython version

MicroPython v1.26.0-preview.261.gbcc8d4ee1.dirty on 2025-06-22; linux [GCC 15.1.1] version

Reproduction

  1. Build mpy-cross with no special flags (make -C mpy-cross clean && make -C mpy-cross)
  2. Compile tests/basics/exception_chain.py into native code (arch does not matter) with mpy-cross -X emit=native -march=debug tests/basics/exception_chain.py
  3. mpy-cross will crash.

Expected behaviour

Compiling tests/basics/exception_chain.py should not crash mpy-cross.

Observed behaviour

mpy-cross crashes with:

mpy-cross: ../py/emitnative.c:2947: emit_native_raise_varargs: Assertion `n_args == 1' failed.`

Additional Information

If having a multi-arg exception is not supported for native code compilation, then an error message should be printed rather than crashing the compiler.

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied