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
Variadic calls: an argument narrower than int is not promoted (i8 -3 arrives as 253) #1849
Found while fixing #1831. A variadic argument narrower than int is passed without C's default argument promotion (C11 6.5.2.2p7: the arguments matched by ... get the default argument promotions — an integer narrower than int becomes int, keeping its sign). Codegen passes the i8/i16 value as is into the LLVM vararg call, where its upper bits are undefined; LLVM gives them no extension.
use c_import("int vsum(int n, ...);")
fn pick(x: i8) -> i8: x
fn pickf(x: f32) -> f32: x
fn main:
let f = pickf(1.5)
let b = pick(-3)
let u: u8 = 200
print(unsafe { vsum(3, f, b, u) })
clang -c vsum.c && with build main.w --link-object vsum.o prints f=1.5 b=253 u=200 (expected b=-3), v0.15.3.0 on darwin arm64: the i8 constant is materialized as mov w9, #0xfd into the 8-byte stack slot. With runtime-computed values the register often happens to hold the extended value, so the bug hides.
Fix: Sema states the promoted type of each ... argument (the same c_default_promoted_type#1831 adds for unprototyped calls) and codegen coerces each variadic argument to it, sign- or zero-extending by the argument's own type, as clang does (sext i8 ... to i32, fpext float ... to double).
Activity
Variadic calls pass each `...` argument after the default argument pr…
The C variadic function-pointer type: extern "C" fn(A, ..., ...) -> R (…