mirror of
https://github.com/apache/nuttx.git
synced 2026-05-09 23:12:17 +08:00
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:
+26
-1
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user