Repository navigation
Conversation
The C backend renames a Flow definition named like a clashing libc function (abs, random, index, div, wait and the rest of flowc_cgen_is_libc_clash) to __flowc_libc_<name> for the whole unit, so every call reaches the Flow function. mlirgen treated such a definition as libc whenever its arity matched libc's, so stdlib/math.flow's abs(x: f32) became libc's integer abs: abs(-0.25) was 0, and tests/cgen/stdlib_math_f32_intrinsics exited 1 where C exits 0. mlg_libc_mode now marks a defined function with one of those names as the program's own (mode 2, emitted as __flowc_libc_<name>), using the C backend's list, now exported from cgen.flow. compiler/fixtures/mlir/libc_clash.flow defines abs and random; the old backend printed 0.000000 1.000000 and exited 1. Corpus digests moved for the programs that define or import such a function.
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Oct 14, 2026
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: godofecht <[email protected]>
Contributor
Author
|
Superseded by #1677 (migration onto current main; CI green). Closing this historical PR. |
Open
19 of 37 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cause
The C backend renames a Flow definition whose name clashes with a libc declaration (
abs,random,index,div,waitand the rest offlowc_cgen_is_libc_clash) to__flowc_libc_<name>for the whole unit, with a#define. Every call then reaches the Flow function.mlirgen's
mlg_libc_modetreated such a definition as libc whenever its arity matched libc's.stdlib/math.flow'sabs(x: f32) -> f32became libc's integerabs, soabs(-0.25)was 0.tests/cgen/stdlib_math_f32_intrinsics.flowexited 1 under MLIR and 0 under C.Fix
mlg_libc_modereturns 2 (the program's own function, emitted and called as__flowc_libc_<name>) for a function with a body whose name is on the C backend's list. The list is the C backend's own:flowc_cgen_is_libc_clashis now exported from cgen.flow and imported by mlirgen.flow.Regression test
compiler/fixtures/mlir/libc_clash.flowdefinesabs(x: f32)andrandom(). The old backend printed0.000000 1.000000 4and exited 1; the recorded run is0.250000 1.500000 4, exit 0, as C prints.Counts (mlir_vs_c, full corpus, --jobs 8, macOS arm64, LLVM 22.1.7)
Now same:
tests/cgen/stdlib_math_f32_intrinsics.flow,examples/circuits/buck_converter.flowand the new fixture, plus two timing cases (examples/ai/flowlm_charlm.flow,tests/cgen/for_variable_step.flow). Five programs that were same were not in this run:examples/concurrency/http_middleware.flow(the C build exited 1),tests/stdlib/test_gpu_model.flow(MLIR exit 133),tests/lang/test_gpu_graph.flow(build timeout), and the two nondet cases seen on every branch (work_steal,test_c_import_string_time). I re-ran the first three with--onlyon this branch's compiler: all same, so those were load or port flakes during the full run.Gates
bootstrap_from_c.sh --regen, then--verify: PASSmlir_math_override, in its C backend half. It fails the same way with a flowc built from main's bootstrap C.Regenerated state
compiler/bootstrap/flowc_stage_a.candflowc_stage_a, in their own last commit.libc_clash.mlirand.out.compiler/fixtures/mlir/corpus.txt: 9 digests move, forlib/stdlib/math.flowand the programs that define or import such a function. The 11 programs main never recorded are left out.The floor in
compiler/mlir_vs_c/floor.txtis not changed.Risk
Low. The only behaviour change is for programs that define one of these names; they now get their own definition under MLIR, as under C.
cgen.flowchanges by oneexportkeyword, so C output is unchanged (tests/cgen goldens pass).