This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 895a9423ee1 tools/mksyscall: fix union illegal type for cast
895a9423ee1 is described below

commit 895a9423ee1e5118ae8f8d9463449db902eaac55
Author: zhangyuan29 <[email protected]>
AuthorDate: Tue Jul 29 19:35:40 2025 +0800

    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]>
---
 tools/mksyscall.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/tools/mksyscall.c b/tools/mksyscall.c
index 2a25a1e005b..953c132f2e1 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 <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
         {

Reply via email to