Skip to content

with migrate refuses fma, frexp, ldexp, isnan and other C99 <math.h> functions #2680

Closed

Description

@joshhickson

A migrated C file that calls a <math.h> function outside D42's builtin table doesn't migrate:

#include <math.h>
double f(double a, double b, double c) { return fma(a, b, c); }
migrate: untranslatable function 'f': bailed at ReturnStmt ...
migrate: unsupported filtered system variable 'fma' from .../bits/mathcalls.h:394:1; add an explicit binding or extend std.libc

Refused the same way: fma, fmin, fmax, fdim, frexp, ldexp, modf, scalbn, nextafter,
remainder, ilogb, logb, lround, llrint. The classification macros fail differently:
isnan, isinf, isfinite, signbit expand to __builtin_isnan etc., and each is "unsupported compiler
builtin '__builtin_isnan': no structural lowering". sqrt, cos and fmod in the same template migrate.

Cause. A libm call passes the system-symbol filter only if it is a row of src/MathBuiltins.w
(ci_is_libm_fn is math_fn_lookup(name) >= 0, src/CImport.w:20946, read by ci_libc_symbol_kind_mask at
:20980; the filter is ci_note_filtered_system_symbol_ref, :21131-21143). The table has the 34 functions of
§17.6a. D42 rules "the full libm surface (specification §17.6a lists it)", and §17.6a's list leaves these out;
std.libc doesn't bind them either. The __builtin_* classification calls fall through to
reject_builtin_call(..., "no structural lowering") (:12504).

Nearly every numeric C library uses these. pocketfft's my_sincosm1pi calls fma 13 times, so the file
doesn't migrate; Cephes uses frexp/ldexp/isnan throughout.

Fix direction (your call). Add the missing C99 functions to the builtin table (fma → llvm.fma,
which mul_add already lowers to; fmin/fmax → llvm.minnum/maxnum; the rest to libm symbols), and
lower the four classification builtins structurally (x != x, x.abs() == inf, …). Or bind them in
std.libc.

Checked on Linux x86_64 (WSL2) with release builds of main 14a720bd and 25ac6ac0; main is now e3b0ad0e, which doesn't touch the libm filter.

Activity

  1. ehartford commented on Oct 26, 2026

    @ehartford
    Contributor

    Very nice feedback thank you!

  2. added this to the post-v0.16.0 milestone on Oct 28, 2026
  3. added a commit that references this issue on Nov 11, 2026
  4. ehartford commented on Nov 11, 2026

    @ehartford
    Contributor

    Fixed in #3257. Root cause: a libm call passed the migrator's system-symbol filter only if it was a row of the builtin table. std.libc now binds the C99 functions outside it (fma, fmin, fmax, fdim, frexp, ldexp, modf, scalbn, nextafter, remainder, logb, ilogb, the rounding family, each with its f form), and isnan/isinf/isfinite/signbit lower to four std.libc functions from Darwin's __inline_*, clang/glibc's __builtin_* and older glibc's __* spellings. Test: c-migrator-basic-tests c99_math migrates and runs a C program using every function. Not covered: the UCRT's _dclass/_dsign spellings on Windows still fail loudly.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions