Skip to content

Emitted code epilogue block contains a superflous jump to the next available code address. #16604

@agatti

Description

@agatti

Port, board and/or hardware

mpy-cross built from git commit 6db2997 (current master)

MicroPython version

MicroPython v1.25.0-preview.216.g6db29978a.dirty on 2025-01-17; mpy-cross emitting mpy v6.3

Reproduction

  1. Run mpy-cross -X emit=native -march=debug tests/basics/0prelim.py
  2. Look at the last part of the output for a jump to label_0.

This applies to any supported architecture with a native emitter, but -march=debug is used in the command line to make the problem visible without using a disassembler.

Expected behaviour

There should be no empty jump being emitted at the end of a block.

Observed behaviour

At the end of an emitted block of code this can be seen (taken from tests/basics/0prelim.py):

    ...
    jump(label_0)
label(label_0)
EXIT(0)

This applies also to functions that need a more involved cleanup procedure:

(tests/basics/async_for.py):

    ...
    jump(label_0)
    dead_code load(r_temp0, r_fun_table, 0)
    dead_code store(r_temp0, r_local2, 5)
    dead_code mov_reg_imm(r_temp0, 40=0x28)
    dead_code add(r_temp0, r_local2)
    dead_code store(r_temp0, r_local2, 2)
    dead_code mov_reg_imm(r_temp0, 0=0x0)
    dead_code mov_local_reg(local_3, r_temp0)
    dead_code jump(label_0)
label(label_0)
    call_ind(nlr_pop)
    mov_reg_local(r_ret, local_3)
EXIT(0)

(tests/basics/array_micropython.py):

    ...
    mov_local_reg(local_3, r_ret)
    jump(label_0)
label(label_0)
    mov_reg_local(r_arg1, local_6)
    call_ind(native_swap_globals)
    call_ind(nlr_pop)
    mov_reg_local(r_ret, local_3)
EXIT(0)

Additional Information

This is not specific to mpy-cross as the same issue occurs when emitting a block of code at runtime as well.

Code of Conduct

Yes, I agree

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy