Repository navigation
cuda-macros: reject a variadic #[device] extern at expansion - #1051
Merged
nihalpasham merged 1 commit intoAug 20, 2026
Merged
Conversation
A variadic device extern was only refused in device codegen, and only when
a kernel actually called it. Two holes:
declared AND called late error, no span, no file, no line
declared, never called compiles clean -- the collector only registers
externs reached from kernel MIR
`...` is purely syntactic, so `generate_device_extern_block` can refuse it
where the user wrote it, next to the existing spanned ABI check:
error: #[device] externs cannot be variadic
--> src/main.rs:8:32
|
8 | fn variadic_helper(x: f32, ...) -> f32;
| ^^^
The codegen rejection stays as-is. The collector recognises device externs
by their reserved name prefix, so a hand-written extern block never passes
through this macro and the backend check is the only gate on that path.
Fixes NVIDIA#876
Collaborator
|
nihalpasham
approved these changes
Aug 20, 2026
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.
Fixes #876, following @nihalpasham's spec in this comment — including both corrections.
The change
generate_device_extern_blocknow refuses...where it is written, six lines modelled on the spanned ABI check just above it:Both holes close together:
The second was the quieter one: the collector only registers externs reached from kernel MIR, so a variadic device extern nobody called went through untouched.
What the user sees now:
What deliberately did not change
c_variadicrejection indevice_codegen.rsstays a real error, not an assertion. The collector detects device externs by their reserved name prefix, so a hand-written extern block never passes through this macro and the backend check is the only gate on that path.char/f128/ arrays-by-value. Those need resolved types —type MyF = f128;or a generic hides the type from a syntactic macro....is the one purely syntactic check, which is why it belongs here.Test plan
tests/compile_fail/device_extern_variadic.{rs,stderr}, modelled ondevice_extern_wrong_abi, and registered it intests/macro_guard.rsbeside it.trybuildagainst the fixture on the pinnednightly-2026-04-03— passes, and the checked-in.stderris the exact output trybuild generated rather than a hand-written guess.cargo fmt --all -- --check— clean.cargo test -p cuda-macrosin full. Its dev-dependency chain reachescuda-bindings, which needscuda.h, and this machine has no CUDA toolkit. The fixture was therefore exercised through a scratch harness depending only oncuda-macros(which is all the fixture uses —use cuda_macros::device;), so the fixture path and hence the-->line in the.stderrmatch whatmacro_guard.rswill produce.