When a Linux kernel API changes, hundreds of drivers are converted by hand over months, and the earlier conversions are reviewed examples for the later ones. We ask whether small open language models running on a laptop can turn such examples into Coccinelle semantic patches, the rules kernel maintainers already use for tree-wide changes. We adapt guided code generation to this task: the training examples are decomposed by script into a tree of change variants, the model writes one small rule per variant under feedback from applying it to the examples, deterministic components repair SmPL syntax and generalise driver-specific names, rules are composed greedily, and a compile critic repairs or rejects a rule whose output does not build. We evaluate on a pre-registered test set of 7 migrations whose new APIs appeared after the training cutoffs of all three models (Qwen2.5-Coder 7B, Llama 3.1 8B, Gemma 3 4B), with 122 held-out driver conversions, counting a conversion as solved only if the rule's output matches the human fix and compiles. With the framework, Qwen2.5-Coder solves 35.3 conversions on average over three seeds (range 32-41), against 1.0 when prompted directly; Spinfer solves 41 and a frontier LLM agent 66. The local model solves fewer conversions than Spinfer but its rules are the most precise on the test set (0.74 of the files they change are solved, against 0.55 for Spinfer and 0.70 for the frontier agent), and the compile critic removes every output that matches the human fix but does not build. The two general-purpose models stay weak even with guidance (at most 12 solved). All code, prompts, model responses and results are released.
Figures & tables
Fig. 1: The four stages. Shaded boxes are deterministic scripts; blue boxes call the local model. Only the training siblings are read; held-out targets are never seen.
Set
Migration
New API
Train
Targets
Buildable
Target dates
dev
ida_simple
–
20
20
20
2022-06–2024-05
dev
i2c_probe_new
–
20
20
19
2023-05–2023-09
dev
platform_remove_new
–
20
20
20
2023-03–2024-05
dev
strlcpy_strscpy
–
20
20
15
2021-01–2023-12
dev
pci_dma_wrappers
–
20
20
20
2020-12–2022-02
test
secs_to_jiffies
2024-10-30
17
10
10
2025-04–2026-05
TABLE I: Data. New API : first commit that adds the new API under include/ (test set only; all after the models’ training cutoffs). Train : training siblings. Buildable : targets whose original file compiles on x86_64 allmodconfig ; the denominator of every success count.
Frontier
Qwen2.5-Coder 7B
Llama 3.1 8B
Gemma 3 4B
Migration
Bld.
LLM †
Spinfer
one-shot
full
one-shot
full
one-shot
full
devm_kmemdup_array
16
1
2
0.0
1.3 [0–2]
0.0
0.0
0.0
0.0
ethtool_rx_ring_count
20
12
0
0.0
0.0
0.0
0.0
0.0
0.0
gpio_set_rv
20
14
0
0.0
0.0
0.0
0.0
0.0
0.0
iio_claim_direct
20
17
16
0.0
16.0
0.0
0.0
0.0
0.0
iio_push_with_ts
20
12
12
1.0
0.7 [0–1]
0.0
0.0
0.0
0.0
TABLE II: Test set: held-out conversions solved (output matches the human fix exactly or as a complete subset, and compiles). Local models: mean over three seeds, [min–max] where the seeds differ. one-shot : one rule from the plain examples; full : the complete framework. † A frontier LLM agent that may have seen these migrations during training; a reference point, not a like-for-like competitor.
Frontier
Qwen2.5-Coder 7B
Llama 3.1 8B
Gemma 3 4B
Migration
Bld.
LLM †
Spinfer
one-shot
full
one-shot
full
one-shot
full
i2c_probe_new
19
19
0
12.7 [0–19]
19.0
0.0
0.0
0.0
0.0
ida_simple
20
14
9
0.0
5.3 [5–6]
0.0
1.7 [0–5]
0.0
3.0 [0–9]
pci_dma_wrappers
20
6
2
0.0
1.3 [0–2]
0.0
0.0
0.0
0.0
platform_remove_new
20
19
0
0.0
0.0
0.0
0.0
0.0
0.0
strlcpy_strscpy
15
14
13
8.7 [0–13]
12.3 [11–13]
0.0
0.0
0.0
0.0
TABLE III: Development set, same layout as Table II . These migrations were used to design the framework, so the numbers are optimistic.
Development (of 94)
Test (of 122)
Configuration
Qwen2.5-Coder
Llama
Gemma
Qwen2.5-Coder
Llama
Gemma
one-shot
21.3 [13–32]
0.0
0.0
1.0
0.0
0.0
+ feedback
21.3 [13–32]
0.0
0.0
1.0
2.0 [0–6]
0.0
+ decomposition
21.7 [13–32]
0.0
0.0
18.0
2.0 [0–6]
0.0
+ guidance
29.0 [21–34]
2.3 [0–7]
0.0
35.3 [32–41]
10.0 [9–12]
0.0
+ auto-repair
38.0 [37–39]
1.7 [0–5]
3.0 [0–9]
35.3 [32–41]
7.0 [0–12]
2.7 [0–8]
TABLE IV: Ablation: conversions solved as components are added (mean over three seeds, [min–max]). Every configuration is composed by stage 3; the last row adds the compile critic of stage 4.
Set
Source
Success
Changed
Divergent
Broken
Precision
dev
Frontier LLM †
72.0
91.0
17.0
0.0
0.79
dev
Spinfer
24.0
47.0
13.0
0.0
0.51
dev
Qwen2.5-Coder 7B, before compile critic
38.0
82.7
12.0
20.0
0.46
dev
Qwen2.5-Coder 7B, full
38.0
62.7
12.0
0.0
0.61
dev
Llama 3.1 8B, before compile critic
1.7
22.3
10.7
0.0
0.07
dev
Llama 3.1 8B, full
1.7
20.7
8.7
0.0
0.08
TABLE V: Precision of the outputs on buildable targets (local models: mean over seeds). Changed : targets the rule edits; Divergent : the rule makes an edit the human did not make; Broken : the output matches the human fix (exactly or as a subset) but does not compile; Precision : solved / changed.
Development
Test
Model
Calls
Seconds
Repairs
Calls
Seconds
Repairs
Qwen2.5-Coder 7B
13.2
21
0.4
9.7
15
0.5
Llama 3.1 8B
16.3
31
0.1
9.7
23
0.0
Gemma 3 4B
17.4
30
0.0
9.7
16
0.3
TABLE VI: Cost per migration of the full configuration on one laptop GPU (RTX 5060, 8 GB): model calls and seconds of generation in stage 2, and repair calls of the compile critic (stage 4), mean over migrations and seeds. Compilation time is excluded.
Large language models (LLMs) have become ubiquitous tools for code generation and editing. However, development teams often use multiple LLM assistants. Different developers may prefer different models, and individual developers may switch between models across different coding sessions. Because of this, the edits any one model makes are frequently applied to foreign code originally generated by another model. These LLMs are often trained on different datasets, and as a result have different stylistic preferences. Do LLMs behave differently when they edit foreign code originally written by a different LLM with a different coding style? We find that models tend to make more, and often excessive, edits on foreign code. We introduce CROCODIL (Cross-model Code Editing with LLMs), a post-training framework for reducing excessive edits while preserving functional correctness. CROCODIL's similarity reward penalizes large changes, while its execution reward scores build and test success. We use the product of these two rewards to encourage the policy to decrease the edit size without decreasing the edit task success rate. CROCODIL is available at https://github.com/EngineeringSoftware/Crocodil.
Large language model (LLM) code-repair systems fix faulty programs by repeatedly generating and testing revisions. Each revision is costly, making the choice of which repair to pursue important for efficiency. Existing search policies rely on test pass rates and search statistics, ignoring the details of test failures and proposed edits. We introduce CodeTriage, a learned policy that prioritizes edits before their revised programs are generated and tested. Its 0.6B-parameter model reads the test output, failure diagnosis, and proposed edit, then predicts a distribution over the number of repair steps needed to reach a fix through that edit. These predictions prioritize all pending edits across programs before generating and testing the revised code. On held-out repair tasks, CodeTriage finds fixes with 21% fewer program revisions and 12% fewer output tokens than the strongest baseline on each metric. Without retraining, it achieves the highest average success across search budgets for each of 11 unseen repair LLMs. Ablations show that both the failure context and edit text, as well as comparisons across programs, improve search. We also release a corpus of 12.2 million program versions from four LLMs, organized into repair trees with proposed edits and test results.
Large language models can generate C code from natural-language descriptions, but resulting programs often contain security vulnerabilities and compilation errors, posing risks for embedded and resource-constrained systems. This work investigates how feedback and retrieval improve reliability of LLM-generated C code. We present an analysis-and-repair workflow that combines compilation diagnostics, CodeQL static analysis, and KLEE symbolic execution with retrieval of prior repair patterns for iterative refinement. Evaluated on 5,000 C programming tasks exercising embedded relevant vulnerabilities, baseline models show substantial reliability gaps, with compilation failure rates up to 46% and security defect rates up to 49%. Our approach improves both metrics. For CodeLlama 7B, security defect rates decrease from 49% to 19% and total CodeQL errors drop from 15,088 to 2,463 (83.7%). For DeepSeek Coder 1.3B, compilation failures are reduced from 42% to 22% and security defects from 35% to 15%. These results show that integrating lightweight analysis tools can improve the safety of LLM-generated code for embedded development.