Skip to content

Commit 973805a

Browse files
committed
tools/mksyscall: fix union illegal type for cast
Some compilers (e.g., Tasking) do not allow forced type casting of unions. Replace the direct cast with memcpy to copy the union parameter into a local variable, avoiding the illegal cast while preserving the correct behavior. Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
1 parent 9ecfff0 commit 973805a

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

tools/mksyscall.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ 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, "#include <string.h>\n");
431432

432433
if (strlen(g_parm[HEADER_INDEX]) > 0)
433434
{
@@ -461,6 +462,26 @@ static void generate_stub(int nfixed, int nparms)
461462

462463
fprintf(stream, ")\n{\n");
463464

465+
/* Fixed union illegal type for cast */
466+
467+
for (i = 0; i < nparms; i++)
468+
{
469+
get_formalparmtype(g_parm[PARM1_INDEX + i], formal);
470+
471+
/* Treat the first argument in the list differently from the others..
472+
* It does not need a comma before it.
473+
*/
474+
475+
if (is_union(formal))
476+
{
477+
fprintf(stream, " %s _parm%d;\n", formal, i + 1);
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+
}
483+
}
484+
464485
/* Then call the proxied function. Functions that have no return value are
465486
* a special case.
466487
*/
@@ -503,7 +524,7 @@ static void generate_stub(int nfixed, int nparms)
503524

504525
if (is_union(formal))
505526
{
506-
fprintf(stream, "(%s)((%s)parm%d)", formal, actual, i + 1);
527+
fprintf(stream, "_parm%d", i + 1);
507528
}
508529
else
509530
{

0 commit comments

Comments
 (0)