Files
buildroot/package/micropython/0002-py-emitinlinextensa-Simplify-register-name-lookup.patch
Thomas Perale 0814b614c2 package/micropython: fix build with GCC 15
A set of `unterminated-string-initialization` errors appeared when
building the micropython package with GCC15 on the host.
The autobuilder failed to build the package micropython with the
following error:

```
CC ../py/emitinlinethumb.c
../py/emitinlinethumb.c:153:9: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (4 chars into 3 available) [-Werror=unterminated-string-initialization]
  153 |     {0, "r0\0"},
      |         ^~~~~~
../py/emitinlinethumb.c:154:9: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (4 chars into 3 available) [-Werror=unterminated-string-initialization]
  154 |     {1, "r1\0"},
      |         ^~~~~~
...
```

This patch adds the set of upstream commits to fix the compatbility with
GCC15 (see [1]).
The patches were backported to micropython v1.22.2. The main difference
with the upstream version is that since the v1.23, the project removed the
use of the `STATIC` macro (see [2]).

Also, in the codebase of v1.22.2 the 'unterminated-string-initialization'
error occured in another file that was reworked in the patch [3] and
included in v1.25. This patch is included as well to remove the error in
v1.22.2.

[1] package/micropython/0003-Fixes-for-GCC-15-1-unterminated-string-literal-warning.patch
[2] decf8e6a8b
[3] package/micropython/0002-py-emitinlinextensa-Simplify-register-name-lookup.patch

Fixes: https://autobuild.buildroot.org/results/fdf/fdf1d7c3e3a51e6fc7fa5abea57de6c9ce792015

Signed-off-by: Thomas Perale <thomas.perale@mind.be>
Signed-off-by: Julien Olivain <ju.o@free.fr>
2025-05-16 16:14:32 +02:00

86 lines
2.9 KiB
Diff

From 7d9fcfcd1b0ef9f20e703037eba6a49a4fc4cb0c Mon Sep 17 00:00:00 2001
From: Alessandro Gatti <a.gatti@frob.it>
Date: Tue, 28 Jan 2025 14:58:29 +0100
Subject: [PATCH] py/emitinlinextensa: Simplify register name lookup.
This commit changes the Xtensa inline assembly parser to use a slightly
simpler (and probably a tiny bit more efficient) way to look up register
names when decoding instruction parameters.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Upstream: https://github.com/micropython/micropython/commit/50fab08e6b861adf65905d6adacd74201c87ddb9
[tperale: backport 1.22.2]
Signed-off-by: Thomas Perale <thomas.perale@mind.be>
---
py/emitinlinextensa.c | 49 +++++++++----------------------------------
1 file changed, 10 insertions(+), 39 deletions(-)
diff --git a/py/emitinlinextensa.c b/py/emitinlinextensa.c
index 5dac2ae39..e59146047 100644
--- a/py/emitinlinextensa.c
+++ b/py/emitinlinextensa.c
@@ -115,50 +115,21 @@ STATIC bool emit_inline_xtensa_label(emit_inline_asm_t *emit, mp_uint_t label_nu
return true;
}
-typedef struct _reg_name_t { byte reg;
- byte name[3];
-} reg_name_t;
-STATIC const reg_name_t reg_name_table[] = {
- {0, "a0\0"},
- {1, "a1\0"},
- {2, "a2\0"},
- {3, "a3\0"},
- {4, "a4\0"},
- {5, "a5\0"},
- {6, "a6\0"},
- {7, "a7\0"},
- {8, "a8\0"},
- {9, "a9\0"},
- {10, "a10"},
- {11, "a11"},
- {12, "a12"},
- {13, "a13"},
- {14, "a14"},
- {15, "a15"},
+STATIC const qstr_short_t REGISTERS[16] = {
+ MP_QSTR_a0, MP_QSTR_a1, MP_QSTR_a2, MP_QSTR_a3, MP_QSTR_a4, MP_QSTR_a5, MP_QSTR_a6, MP_QSTR_a7,
+ MP_QSTR_a8, MP_QSTR_a9, MP_QSTR_a10, MP_QSTR_a11, MP_QSTR_a12, MP_QSTR_a13, MP_QSTR_a14, MP_QSTR_a15
};
-// return empty string in case of error, so we can attempt to parse the string
-// without a special check if it was in fact a string
-STATIC const char *get_arg_str(mp_parse_node_t pn) {
- if (MP_PARSE_NODE_IS_ID(pn)) {
- qstr qst = MP_PARSE_NODE_LEAF_ARG(pn);
- return qstr_str(qst);
- } else {
- return "";
- }
-}
-
STATIC mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) {
- const char *reg_str = get_arg_str(pn);
- for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(reg_name_table); i++) {
- const reg_name_t *r = &reg_name_table[i];
- if (reg_str[0] == r->name[0]
- && reg_str[1] == r->name[1]
- && reg_str[2] == r->name[2]
- && (reg_str[2] == '\0' || reg_str[3] == '\0')) {
- return r->reg;
+ if (MP_PARSE_NODE_IS_ID(pn)) {
+ qstr node_qstr = MP_PARSE_NODE_LEAF_ARG(pn);
+ for (size_t i = 0; i < MP_ARRAY_SIZE(REGISTERS); i++) {
+ if (node_qstr == REGISTERS[i]) {
+ return i;
+ }
}
}
+
emit_inline_xtensa_error_exc(emit,
mp_obj_new_exception_msg_varg(&mp_type_SyntaxError,
MP_ERROR_TEXT("'%s' expects a register"), op));
--
2.49.0