tools/mksyscall: fix union illegal type for cast#18360
Draft
zyfeier wants to merge 1 commit intoapache:masterfrom
Draft
tools/mksyscall: fix union illegal type for cast#18360zyfeier wants to merge 1 commit intoapache:masterfrom
zyfeier wants to merge 1 commit intoapache:masterfrom
Conversation
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>
anchao
requested changes
Feb 6, 2026
|
|
||
| /* Fixed union illegal type for cast */ | ||
|
|
||
| for (i = 0; i < nparms; i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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