Skip to content

lib/math32: Avoid __uint128_t casts for LDC ImportC#19497

Merged
acassis merged 1 commit into
apache:masterfrom
ML-dev-crypto:fix-hello-d-importc-casts
Jul 21, 2026
Merged

lib/math32: Avoid __uint128_t casts for LDC ImportC#19497
acassis merged 1 commit into
apache:masterfrom
ML-dev-crypto:fix-hello-d-importc-casts

Conversation

@ML-dev-crypto

Copy link
Copy Markdown
Contributor

Summary

Building the hello_d example with LDC ImportC fails because ImportC does not correctly handle direct __uint128_t C-style casts such as (__uint128_t)a and (__uint128_t)1 used in include/nuttx/lib/math32.h.

These expressions compile successfully with the existing implementation, but ImportC fails while parsing them, preventing the D example from building.

Rewrite the affected expressions to initialize __uint128_t variables first and then perform the arithmetic. This preserves the existing behavior while allowing the code to compile successfully with LDC ImportC.

Impact

Rewrite the two direct __uint128_t cast expressions in math32.h to use initialized __uint128_t variables before the arithmetic operations.

The computation remains unchanged while avoiding the current ImportC parser limitation.

Testing

Host: WSL2 Ubuntu 24.04 x86_64

Configuration: sim:nsh

Enabled CONFIG_EXAMPLES_HELLO_D.

Before this change, the build failed while compiling include/nuttx/lib/math32.h with LDC ImportC.

After applying this change, the project built successfully.

Verified the application from NSH:

nsh> hello_d
Hello World, [skylake]!
hello_d_main: Saying hello from the dynamically constructed instance
HelloWorld: mSecret=1630678024
DHelloWorld.HelloWorld: CONSTRUCTION FAILED!
Constructor
hello_d_main: Saying hello from the instance constructed on the stack
HelloWorld: mSecret=42
DHelloWorld.HelloWorld: Hello, World!!
Destructor

Building the hello_d example with LDC ImportC fails because ImportC
does not correctly handle direct __uint128_t C-style casts such as
(__uint128_t)a and (__uint128_t)1.

Replace the direct casts with equivalent typed temporaries, preserving
the existing behavior while allowing hello_d to build successfully with
LDC ImportC.

Verified on sim:nsh with CONFIG_EXAMPLES_HELLO_D=y:

  nsh> hello_d
  Hello World, [skylake]!
  DHelloWorld.HelloWorld: Hello, World!!

Signed-off-by: Ansh Rai <anshrai331@gmail.com>
@github-actions github-actions Bot added the Size: XS The size of the change in this PR is very small label Jul 21, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@acassis
acassis merged commit d0651aa into apache:master Jul 21, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants