diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index fd810e07b8..1877a01437 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -30,6 +30,13 @@ #define MICROPY_EMIT_XTENSAWIN (1) #endif +// workaround for xtensa-esp32-elf-gcc esp-2020r3, which can generate wrong code for loops +// see https://github.com/espressif/esp-idf/issues/9130 +// this was fixed in newer versions of the compiler by: +// "gas: use literals/const16 for xtensa loop relaxation" +// https://github.com/jcmvbkbc/binutils-gdb-xtensa/commit/403b0b61f6d4358aee8493cb1d11814e368942c9 +#define MICROPY_COMP_CONST_FOLDING_COMPILER_WORKAROUND (1) + // optimisations #define MICROPY_OPT_COMPUTED_GOTO (1) diff --git a/py/parse.c b/py/parse.c index 3972893cbb..14f5f6c105 100644 --- a/py/parse.c +++ b/py/parse.c @@ -639,6 +639,11 @@ STATIC MP_DEFINE_CONST_MAP(mp_constants_map, mp_constants_table); STATIC void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args); #if MICROPY_COMP_CONST_FOLDING +#if MICROPY_COMP_CONST_FOLDING_COMPILER_WORKAROUND +// Some versions of the xtensa-esp32-elf-gcc compiler generate wrong code if this +// function is static, so provide a hook for them to work around this problem. +MP_NOINLINE +#endif STATIC bool fold_logical_constants(parser_t *parser, uint8_t rule_id, size_t *num_args) { if (rule_id == RULE_or_test || rule_id == RULE_and_test) {