Skip to content

tools/mksyscall: fix union illegal type for cast#18360

Draft
zyfeier wants to merge 1 commit intoapache:masterfrom
zyfeier:syscall-fix-union-cast
Draft

tools/mksyscall: fix union illegal type for cast#18360
zyfeier wants to merge 1 commit intoapache:masterfrom
zyfeier:syscall-fix-union-cast

Conversation

@zyfeier
Copy link
Contributor

@zyfeier zyfeier commented Feb 6, 2026

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.

Note: Please adhere to Contributing Guidelines.

Summary

Some compilers (e.g., Tasking) do not allow forced type casting of unions in generated syscall stub files. The mksyscall tool previously generated code like (union_type)((uintptr_t)parm), which is illegal on strict compilers.

This patch replaces the direct union cast with memcpy to copy the uintptr_t parameter into a local union variable, avoiding the illegal cast while preserving correct behavior.

Changed file:
mksyscall.c

Impact

No breaking changes — only affects generated stub code for union-type parameters
Improves compiler compatibility (Tasking and other strict C compilers)
No functional behavior change at runtime

Testing

Build host: Ubuntu Linux x86_64
Target: Tasking compiler toolchain

Steps:
Configured NuttX with a board that uses syscalls with union parameters
Ran make to generate stub files via mksyscall
Verified generated STUB files no longer contain direct union casts
Verified generated code uses memcpy for union parameters
Build completed without illegal type for cast or incompatible types at assignment errors
Verification checklist:

Generated stub files compile without errors on Tasking compiler
No regression on GCC/Clang builds
Union parameter values correctly passed through syscall interface

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>
@github-actions github-actions bot added Area: Tooling Size: S The size of the change in this PR is small labels Feb 6, 2026

/* Fixed union illegal type for cast */

for (i = 0; i < nparms; i++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add compiler check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Tooling Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants