You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
C migrator: a declaration-only unprototyped function (int f();) is emitted variadic — wrong ABI in migrated code #1848
Found while fixing #1831. The C migrator emits a declaration-only unprototyped function (int knr();, no definition in the unit) as a variadic extern, so every migrated call uses the variadic convention — on darwin arm64 the arguments go on the stack while the definition reads x0/x1.
C11 6.5.2.2p6: an unprototyped call passes its default-promoted arguments with the fixed-argument convention. #1831 fixed c_import: its generated text states the fact in a manifest line (// @with-cimport-unprototyped|knr) that only the Frontend reads while parsing c_import output, and it sets NK_EXTERN_FN flag bit 1; Sema records each call's promoted argument types and codegen builds the call's FnAbi from them. Migrated source is ordinary user source, so it has no spelling for this.
CiMigrate.w's declaration-only branch (fn_cursor < 0 or not a definition) still takes with_cimport_fn_is_variadic, which is true for every FunctionNoProto type.
Recommended fix: the migrator sees every call site's promoted argument types in clang's AST (the ImplicitCastExpr on each argument). When every call in the unit agrees, emit the prototype C actually uses, extern fn knr(a0: c_int, a1: c_int) -> c_int; when they disagree, or the function is used as a value, fail the migration loudly naming the function (No Silent Fallbacks). Never emit (...).
Activity
c_import: an unprototyped call passes promoted arguments with the fix…
C migrator: a declaration without a prototype becomes the prototype i…