Skip to content

c_import: a call through an unprototyped declaration (int f();) uses the variadic convention — wrong arguments on darwin arm64 #1831

Closed

Description

@ehartford

libclang reports every FunctionNoProto type as variadic, so int knr(); is imported as extern fn knr(...) -> c_int and its calls use the variadic calling convention. A K&R definition is not variadic: on darwin arm64 the variadic convention puts every argument on the stack while the definition reads x0/x1.

// knr.c
int knr(a, b) int a, b; { return a * 10 + b; }
use c_import("int knr();")
fn main:
    print(unsafe { knr(4, 2) })

clang -c knr.c && with build main.w --link-object knr.o → prints 0 (expected 42).

C calls an unprototyped function with the non-variadic convention after the default argument promotions. The D75 branch (#1678) fixes the definition side (a K&R definition in the unit is no longer imported as fn f(...)), but a declaration-only no-proto function still takes this path. Modeling it needs either a per-call promoted non-variadic signature or a loud refusal of calls with arguments; never the variadic ABI.

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