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 <zhangyuan29@xiaomi.com>
This commit is contained in:
zhangyuan29
2025-07-29 19:35:40 +08:00
committed by Xiang Xiao
parent 81d57ad5d5
commit 895a9423ee
+26 -1
View File
@@ -428,6 +428,9 @@ static void generate_stub(int nfixed, int nparms)
g_parm[0]);
fprintf(stream, "#include <nuttx/config.h>\n");
fprintf(stream, "#include <stdint.h>\n");
fprintf(stream, "#ifdef CONFIG_ARCH_TOOLCHAIN_TASKING\n");
fprintf(stream, "#include <string.h>\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
{