Skip to content

codegen: accept char in device-extern signatures - #1179

Merged
nihalpasham merged 3 commits into
mainfrom
maint/issue-875-char-device-extern
Aug 24, 2026
Merged

nihalpasham merged 3 commits into
mainfrom
maint/issue-875-char-device-extern

Conversation

@nihalpasham

Copy link
Copy Markdown
Collaborator

Closes #875.

This independently lands the sound ABI change proposed by @NgoQuocViet2001 in #1049 on a signed maintainer branch; the contributor fork does not allow maintainer edits.

Before, a #[device] extern "C" taking or returning Rust char was rejected. After, char uses the same plain 32-bit slot as CUDA C++ unsigned int in parameter, result, and pointee positions.

The device-FFI example now exercises parameter, return, and pointer forms. Its checked-in shape gate builds both the legacy sm_90 and modern sm_100 NVVM paths and rejects signext/zeroext, which the functional round-trip alone cannot detect.

Local checks: 27 rustc-codegen tests, strict clippy for the backend and example, formatting/SPDX/shell checks, and both exact NVVM-IR paths pass.

Map Rust char to a plain i32 across parameter, result, and pointee positions. Extend device_ffi_test with a char parameter/return/pointer case and a dual sm_90/sm_100 IR gate that rejects extension attributes.

This independently lands and credits the sound compiler change proposed by @NgoQuocViet2001 in #1049.

Closes #875

Signed-off-by: nihalp <[email protected]>
@nihalpasham nihalpasham added bug Something isn't working codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Aug 24, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator Author

Reproduced the gap, and @NgoQuocViet2001 had the compiler mapping right in #1049: Rust char is a plain 32-bit device-extern slot, with no extension attribute.

I landed it independently on this signed maintainer branch because the contributor fork does not allow maintainer edits. I kept the parameter/return example and added the pointer form plus a checked-in dual-path IR gate. The deliberate ZeroExtInteger(32) mutation fails the legacy path and is rejected by the modern sm_100 shape assertion.

Exact head 889737ff passes every hosted check, including strict clippy, docs, CodeQL, the complete unit matrix, and the 22-minute GPU-less example compile. No GPU was available locally; the original parameter/return case was also exercised by the contributor on an RTX 5090.

This closes #875 and supersedes #1049.

@nihalpasham
nihalpasham merged commit b22efa9 into main Aug 24, 2026
51 checks passed
@nihalpasham
nihalpasham deleted the maint/issue-875-char-device-extern branch September 5, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working codegen Device code-generation pipeline (Rust MIR to IR to PTX)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

char is rejected in #[device] extern signatures

1 participant