Skip to content

c_import: inline variadic va_start/va_arg body omitted; extern suggestion cannot link it #1678

Closed

Description

@ehartford

While building the #1652 failure/cleanup integration fixture, a minimal inline variadic C function is omitted rather than translated:

use c_import("#include <stdarg.h>\nstatic inline int probe(int n, ...) { va_list ap; va_start(ap, n); int x = va_arg(ap, int); va_end(ap); return x; }")
fn main: print(unsafe { probe(1, 7) })

with run reports c_import symbol 'probe' was omitted: inline body translation failed, categorized as raw-modelable, and suggests a manual extern binding. That remedy cannot link this static inline definition. The reporter is src/CImport.w:1674; the precise unsupported translation branch is not yet diagnosed.

Observed with modeled-C stack stage1 based on 590aa2b (compiler source code identical to the prior 39eb1c4 iteration apart from documentation). Repro/log: modeled-c-completion/out/variadic-inline-probe.w and .log. The #1652 suite needs a controllably failing foreign setter, so this is also a fixture-tooling capability gap. Do not silently emit a fixed-arity definition or a placeholder body for a variadic function.

Related diagnostic classification work: #582. This is separate from the modeled variadic call-site work in #1652.

Activity

  1. ehartford commented on Sep 27, 2026

    @ehartford
    ContributorAuthor

    Ruling (Eric, 2026-09-27, "fair. I agree."): deferred, with the shape settled.

    • Today's behavior is correct: an inline body that uses va_start/va_arg is omitted loudly with the real reason ("va_arg is not supported"), never stubbed; calling variadic C and declaring c_va_list functions keep working.
    • When a migrated library needs a variadic definition, the shape is Zig's: a ... trailing parameter on a With function (library-maintainer tier, never in application code), a va_start intrinsic lowered to LLVM's llvm.va_start (the prologue spill is LLVM's/C's, no assembly), and va_arg[T](ap) expanded per target in With over the c_va_list layouts va_list is modeled as a pointer on every target: a variadic With definition corrupts its stack on linux x86_64 (and linux aarch64) — zlib's gzprintf crashes the drift harness #1104 already models (as clang expands it). The migrator then translates such bodies.
    • Rejected: fixed-arity specialization of variadic bodies (a silent semantic change).

    Spec text lands with the implementation. Refs #1104.

  2. ehartford commented on Sep 29, 2026

    @ehartford
    ContributorAuthor

    Landed in #1844 (main 173d8aa, D75 spec v7.7): With variadic definitions (..., va_start(), ap.arg[T]() per target) and the migrator translating C variadic bodies. Evidence with the installed v0.15.3.0-g173d8aa4d: behav_variadic_definitions.w, behav_variadic_definition_target_abi.w, behav_variadic_definition_called_from_c.w, behav_migrate_variadic_definitions.w and behav_c_import_static_inline_variadic.w all pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions