Commit a135ad2f

a135ad2f5989Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified

Description

Convert a Bigint argument to a scalar at the FFI integer-arg boundary

An integer-typed FFI argument (ffi_func :f, [:int], ...) emitted ((int)(expr)) for any non-poly operand. When the operand was an overflow-promoted integer (sp_Bigint *), that cast the pointer to int rather than the integer value: a -Wpointer-to-int-cast warning and a wrong runtime value (and, under a strict toolchain, a hard error).

This is what blocked tep: Sock.sphttp_sleep_ms(backoff) where backoff comes from a retry loop (d = d * @multiplier) that the analyzer promotes to Bigint. Narrow it through sp_bigint_to_int so the FFI call receives the integer the C function expects.

Refs #1409

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
a135ad2f5989
Parent
6191a06ecdba

src/codegen_call.cmodifiedView file

@@ -2951,6 +2951,13 @@
29512951 buf_puts(&call_buf, "(("); buf_puts(&call_buf, ffi_c_type(spec)); buf_puts(&call_buf, ")(");
29522952 emit_expr(c, argv[ai], &call_buf); buf_puts(&call_buf, ").v.i)");
29532953 }
2954+ else if (at == TY_BIGINT) {
2955+ /* An overflow-promoted integer (e.g. a backoff computed by
2956+ repeated *2) arrives as sp_Bigint*. Narrow it to the C
2957+ integer the FFI arg expects, not the pointer value. */
2958+ buf_puts(&call_buf, "(("); buf_puts(&call_buf, ffi_c_type(spec)); buf_puts(&call_buf, ")sp_bigint_to_int(");
2959+ emit_expr(c, argv[ai], &call_buf); buf_puts(&call_buf, "))");
2960+ }
29542961 else { buf_puts(&call_buf, "(("); buf_puts(&call_buf, ffi_c_type(spec)); buf_puts(&call_buf, ")("); emit_expr(c, argv[ai], &call_buf); buf_puts(&call_buf, "))"); }
29552962 }
29562963 }