Repository navigation
Report variadic functions with a non-C ABI as unsupported - #4836
Merged
tautschnig merged 7 commits intoSep 30, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Non-C variadics can still trigger the compiler assertion through function pointers and reified foreign functions.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Prevents compiler aborts for direct non-C variadic calls by reporting them as unsupported and improves autoharness diagnostics.
Changes:
- Detects unsupported non-C variadic ABIs before stable ABI conversion.
- Generates unsupported stubs for definitions, calls, and foreign declarations.
- Adds target-gated regression and C-variadic compatibility coverage.
| File | Description |
|---|---|
kani-compiler/src/kani_middle/mod.rs |
Detects unsupported internal ABIs. |
kani-compiler/src/kani_middle/codegen_units.rs |
Adds the autoharness skip reason. |
kani-compiler/src/codegen_cprover_gotoc/context/goto_ctx.rs |
Exposes detection through codegen context. |
kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs |
Avoids stable ABI conversion for declarations. |
kani-compiler/src/codegen_cprover_gotoc/codegen/statement.rs |
Reports unsupported direct calls. |
kani-compiler/src/codegen_cprover_gotoc/codegen/function.rs |
Generates unsupported function bodies. |
kani-compiler/src/codegen_cprover_gotoc/codegen/foreign_function.rs |
Adds foreign-function signature fallback. |
kani-driver/src/autoharness/mod.rs |
Displays the new skip reason. |
kani_metadata/src/lib.rs |
Defines unsupported-variadic metadata. |
tests/script-based-pre/autoharness_variadic_abi/config.yml |
Configures regression test execution. |
tests/script-based-pre/autoharness_variadic_abi/check.sh |
Runs target-gated checks. |
tests/script-based-pre/autoharness_variadic_abi/expected |
Records portable expected output. |
tests/script-based-pre/autoharness_variadic_abi/variadic.rs |
Exercises autoharness diagnostics. |
tests/script-based-pre/autoharness_variadic_abi/calls_variadic.rs |
Exercises defined and foreign calls. |
tests/script-based-pre/autoharness_variadic_abi/c_variadic.rs |
Confirms C-variadic behavior remains unchanged. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
`kani autoharness` on a crate containing `unsafe extern "sysv64" fn(_: ...)`
aborted with an assertion from inside `rustc_public`:
assertion failed: !self.c_variadic || matches!(self.conv, CanonAbi::C)
`rustc_public` only models C-variadics whose calling convention canonicalizes
to C, so asking any other variadic for its stable ABI takes the compilation
down. Rust allows those functions, and a hand-written harness that calls one
ICEd just the same -- autoharness only made it easy to hit, by making every
function reachable.
Check the *internal* ABI (exact about the calling convention, unlike the
`extern` string, which canonicalizes per target) before asking for the stable
one, and declare such a function from its signature with an
unsupported-construct body instead. Calls to it, and foreign declarations of
it, report the same unsupported construct, so a harness that cannot avoid one
fails with a message rather than crashing, and harnesses that never reach it
still verify.
C-variadics keep working (tests/kani/FunctionCall/Variadic).
Resolves model-checking#4817
Two follow-ups to the previous commit. Autoharness already skipped these functions, but blamed the wrong thing: "Missing Arbitrary implementation for argument(s) _: std::ffi::VaList<'_>", which reads as though an `Arbitrary` implementation would unblock them. Kani cannot model the call at all, so report the calling convention instead (`AutoHarnessSkipReason::UnsupportedVariadic`). C-variadics keep the `VaList` reason, which is accurate for them: Kani can call one, it just cannot generate the argument. The earlier `tests/expected/variadic-non-c-abi` test broke CI on aarch64, where rustc rejects `...` for every non-C ABI, so the file did not compile. Replaced by a script-based test that asserts the two x86-64-only behaviours inside the script and leaves the `expected` file to the part that holds on every target, since that file has to match everywhere. The predicate moved to `kani_middle` so the backend and autoharness share one definition.
Copilot review caught two shapes the first pass missed, and both still aborted compilation: - a call through `unsafe extern "sysv64" fn(u32, ...)`: the function-pointer branch of `codegen_funcall` converts `fn_abi_of_fn_ptr` with the same stable conversion that asserts. It now checks the internal ABI of the pointer's signature first, through a sibling of `is_unsupported_variadic` that takes a signature rather than an instance. - reifying a foreign one without calling it: that builds an FFI shim, whose body reads the calling convention off the unavailable ABI. The shim now takes the convention from the declaration. Two consequences of declaring these functions from their signature, both found by running the new cases rather than by reading: - CBMC rejects a function *definition* whose parameters are unnamed, and then whose parameter names are not symbols. Since Kani cannot model the body anyway, leave the symbol a declaration instead of giving it a stub body; calls are already replaced by unsupported-construct stubs, so nothing reaches it. - the FFI shim does get a body, so its parameters are declared as named symbols the way the regular path declares them. Taking the address of one without calling it now verifies, which is right: no unsupported construct is reached. The new test asserts that too, so a future change cannot turn address-taking into a spurious failure.
feliperodri
force-pushed
the
fix-4817-variadic-non-c-abi
branch
from
September 24, 2026 00:42
90982e8 to
cdcc503
Compare
10 of 42 tasks
# Conflicts: # kani-compiler/src/kani_middle/codegen_units.rs # kani-compiler/src/kani_middle/mod.rs
# Conflicts: # kani-driver/src/autoharness/mod.rs
`is_unsupported_variadic` runs on every direct call, every function codegen and every function type, but almost no instance is variadic. Check the stable signature's `c_variadic` flag first, so that only variadic instances pay for the internal conversion and the `fn_abi_of_instance` lookup. Same for the function-pointer variant. Co-authored-by: Kiro <[email protected]>
`codegen_function` transformed the body and set up the current function only to discard both for a non-C variadic. Check first, so neither the body transformation nor `reset_current_fn` is needed on that path. Co-authored-by: Kiro <[email protected]>
tautschnig
approved these changes
Sep 30, 2026
tautschnig
enabled auto-merge
September 30, 2026 11:31
Merged
via the queue into
model-checking:main
with commit Sep 30, 2026
e8e1e1f
32 of 34 checks passed
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.

kani autoharnesson a crate containingunsafe extern "sysv64" fn(_: ...)aborts with an assertion from inside the compiler itself (#4817):rustc_publiconly models C-variadics whose calling convention canonicalizes to C, so asking any other variadic for its stable ABI takes the whole compilation down. Two things about the report are worth correcting: it isn't autoharness-specific — a hand-written harness calling such a function ICEs identically, autoharness just makes every function reachable — and it isn't variadics in general:extern "C"variadics work today and keep working.So Kani now checks the internal ABI before asking for the stable one, and treats the unsupported shape as an unsupported construct: the function is declared from its signature with a stub body, and calls to it (or foreign declarations of it) report "Variadic function with a non-C calling convention is not currently supported by Kani". A harness that reaches one fails with that message; harnesses that don't still verify.
Why the internal ABI and not the
extern "sysv64"string: the mapping fromexternstring to calling convention is target-dependent (extern "system"andextern "cdecl"canonicalize differently per platform, seerustc_target/src/spec/abi_map.rs), so a string check would be wrong on some targets.Autoharness also reports these functions better now. It already skipped them, but blamed the wrong thing — "Missing Arbitrary implementation for argument(s)
_: std::ffi::VaList<'_>", which reads as though anArbitraryimplementation would unblock them. It wouldn't; Kani cannot model the call at all. C-variadics keep theVaListreason, which is their real blocker: Kani can call one (tests/kani/FunctionCall/Variadic), it just cannot generate the argument.This is a workaround for an upstream gap, not the end state —
rustc_publiccould model these conventions instead of asserting, and its stable enum already has theX86_64SysVvariant to do it. Filed upstream as rust-lang/rust#163233, and #4843 tracks what real support would take on our side (plus the separateVaListgeneration gap).One thing worth a look: the test gating. The construct only exists on x86-64 — rustc rejects
...for every non-C ABI elsewhere, andsysv64isn't even a valid ABI on aarch64 — and compiletest has no target directives, so the two x86-64-only assertions live insidecheck.shwhile theexpectedfile pins only what holds on every target. My first attempt was anexpected-suite test, which promptly broke the aarch64 CI job. If you'd rather have target gating in compiletest, that's a better fix, but it's test infrastructure I didn't want to bundle in here.Verified on x86-64, merged onto main 358baf8: the reported command completes,
script-based-preis 85/85 with the new test,expected487/487,kani617/617,cargo-kani71/71, and C-variadics still verify.Resolves #4817
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.