From 74ddc1027754e5a323bbb25f683b70f88396bfa0 Mon Sep 17 00:00:00 2001 From: zhangyuan29 Date: Tue, 29 Jul 2025 19:35:40 +0800 Subject: [PATCH] tools/mksyscall: fix union illegal type for cast Some compilers (e.g., Tasking) do not allow forced type casting of unions. When CONFIG_ARCH_TOOLCHAIN_TASKING is enabled, replace the direct cast with memcpy to copy the union parameter into a local variable, avoiding the illegal cast while preserving the correct behavior. Other compilers still use the original cast approach. Signed-off-by: zhangyuan29 --- tools/mksyscall.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tools/mksyscall.c b/tools/mksyscall.c index 2a25a1e005ba8..953c132f2e114 100644 --- a/tools/mksyscall.c +++ b/tools/mksyscall.c @@ -428,6 +428,9 @@ static void generate_stub(int nfixed, int nparms) g_parm[0]); fprintf(stream, "#include \n"); fprintf(stream, "#include \n"); + fprintf(stream, "#ifdef CONFIG_ARCH_TOOLCHAIN_TASKING\n"); + fprintf(stream, "#include \n"); + fprintf(stream, "#endif\n"); if (strlen(g_parm[HEADER_INDEX]) > 0) { @@ -461,6 +464,28 @@ static void generate_stub(int nfixed, int nparms) fprintf(stream, ")\n{\n"); + /* Fixed union illegal type for cast */ + + for (i = 0; i < nparms; i++) + { + get_formalparmtype(g_parm[PARM1_INDEX + i], formal); + get_actualparmtype(g_parm[PARM1_INDEX + i], actual); + + if (is_union(formal)) + { + fprintf(stream, " %s _parm%d;\n", formal, i + 1); + fprintf(stream, "#ifdef CONFIG_ARCH_TOOLCHAIN_TASKING\n"); + fprintf(stream, " memcpy((FAR void *)&_parm%d, " + "(FAR void *)&parm%d,\n" + " sizeof(uintptr_t));\n", + i + 1, i + 1); + fprintf(stream, "#else\n"); + fprintf(stream, " _parm%d = (%s)((%s)parm%d);\n", + i + 1, formal, actual, i + 1); + fprintf(stream, "#endif\n"); + } + } + /* Then call the proxied function. Functions that have no return value are * a special case. */ @@ -503,7 +528,7 @@ static void generate_stub(int nfixed, int nparms) if (is_union(formal)) { - fprintf(stream, "(%s)((%s)parm%d)", formal, actual, i + 1); + fprintf(stream, "_parm%d", i + 1); } else {