Skip to content

Commit 00d05df

Browse files
committed
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 <[email protected]>
1 parent 9ecfff0 commit 00d05df

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tools/mksyscall.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ static void generate_stub(int nfixed, int nparms)
428428
g_parm[0]);
429429
fprintf(stream, "#include <nuttx/config.h>\n");
430430
fprintf(stream, "#include <stdint.h>\n");
431+
fprintf(stream, "#ifdef CONFIG_ARCH_TOOLCHAIN_TASKING\n");
432+
fprintf(stream, "#include <string.h>\n");
433+
fprintf(stream, "#endif\n");
431434

432435
if (strlen(g_parm[HEADER_INDEX]) > 0)
433436
{
@@ -461,6 +464,28 @@ static void generate_stub(int nfixed, int nparms)
461464

462465
fprintf(stream, ")\n{\n");
463466

467+
/* Fixed union illegal type for cast */
468+
469+
for (i = 0; i < nparms; i++)
470+
{
471+
get_formalparmtype(g_parm[PARM1_INDEX + i], formal);
472+
get_actualparmtype(g_parm[PARM1_INDEX + i], actual);
473+
474+
if (is_union(formal))
475+
{
476+
fprintf(stream, " %s _parm%d;\n", formal, i + 1);
477+
fprintf(stream, "#ifdef CONFIG_ARCH_TOOLCHAIN_TASKING\n");
478+
fprintf(stream, " memcpy((FAR void *)&_parm%d, "
479+
"(FAR void *)&parm%d,\n"
480+
" sizeof(uintptr_t));\n",
481+
i + 1, i + 1);
482+
fprintf(stream, "#else\n");
483+
fprintf(stream, " _parm%d = (%s)((%s)parm%d);\n",
484+
i + 1, formal, actual, i + 1);
485+
fprintf(stream, "#endif\n");
486+
}
487+
}
488+
464489
/* Then call the proxied function. Functions that have no return value are
465490
* a special case.
466491
*/
@@ -503,7 +528,7 @@ static void generate_stub(int nfixed, int nparms)
503528

504529
if (is_union(formal))
505530
{
506-
fprintf(stream, "(%s)((%s)parm%d)", formal, actual, i + 1);
531+
fprintf(stream, "_parm%d", i + 1);
507532
}
508533
else
509534
{

0 commit comments

Comments
 (0)