Skip to content

c_import: a static inline function that calls a raw prototype (e.g. a variadic one) does not compile #1830

Closed

Description

@ehartford

A static inline body that calls a raw c_import function is translated as a safe fn with the raw call unwrapped, so the translation fails Sema:

use c_import("int vd_sum(int n, ...);\nstatic inline int vd_call_sum(void) { return vd_sum(4, 10, 20, 12, 18); }\n")
fn main:
    print(vd_call_sum())
error: raw c_import function call requires unsafe context
34 |     return vd_sum((4 as c_int), 10, 20, 12, 18)

(v0.15.2.1 and the D75 branch.) ci_translate_function decides si_raw (→ unsafe fn) from the inline function's own signature only; the migrate path wraps raw calls via g_migrate_unsafe_extern_fn_names, which c_import never fills. Per D51 the inline wrapper should not become safe by inference: the translated function should be unsafe fn when its body calls a raw function (or translation should fail loudly naming the raw callee), never compile-fail on generated text.

Found while writing the C-caller test for D75 variadic definitions (#1678); that test uses a C harness linked with --link-object instead.

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