AdaTrans: Automated C-to-Rust Transformation via Error-Adaptive Repair DOI: XXXXXXX.XXXXXXX Journal: TOSEM

Xiaofan Liu, Zhuang Zhao, Zecan Li, Ziqi Shuai, Yanming Yang, Qi Xin, Jifeng Xuan · 2026

Read AdaTrans: Automated C-to-Rust Transformation via Error-Adaptive Repair DOI: XXXXXXX.XXXXXXX Journal: TOSEM by Xiaofan Liu, Zhuang Zhao, Zecan Li, Ziqi Shuai, Yanming Yang, Qi Xin, Jifeng Xuan (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2606-31706.txt.

Introduction

Liu and six colleagues present AdaTrans, a system that converts C code into Rust automatically. Rust enforces strict ownership and borrowing rules, and language models often break them or hide inside unsafe blocks. Compiler feedback could guide repairs, yet earlier tools use it weakly and rarely check that safety was truly kept.

AdaTrans maps compiler errors to repair strategies through retrieval, sorts diagnostics into semantic categories, and adjusts sampling per category while watching for stagnation. A validation pipeline then checks both compilation and functional equivalence. On 104 contest problems it reaches a mean compilation pass rate of 95.51 percent across runs, with a solve rate near 81 percent under fuzz testing. Unsafe code stays rare, at about 1.19 percent of files.

Catalog record

CREATORXiaofan Liu, Zhuang Zhao, Zecan Li, Ziqi Shuai, Yanming Yang, Qi Xin, Jifeng Xuan
YEAR2026
COLLECTIONPAPERS
FORMATTXT
FILE SIZE110 KB
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2606.31706

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

AdaTrans: Automated C-to-Rust Transformation via Error-Adaptive Repair DOI: XXXXXXX.XXXXXXX Journal: TOSEM Xiaofan Liu, Zhuang Zhao, Zecan Li, Ziqi Shuai, Yanming Yang, Qi Xin, Jifeng Xuan Abstract . Automated transformation of C to Rust remains challenging due to the strict ownership system and borrowing semantics of Rust. Large language models (LLMs) show potential for code generation, but frequently produce Rust code that violates ownership rules or relies on unsafe blocks. Three factors compound this problem. First, the ownership system of Rust presents a semantic barrier that general-purpose LLMs cannot reliably cross. Second, existing approaches underutilize compiler feedback for program repair. Third, without targeted verification, generated code tends to circumvent safety constraints rather than satisfy them. We propose AdaTrans, a framework that addresses these challenges by integrating three mechanisms. First, a Strategy-Driven Retrieval-Augmented Generation (RAG) mechanism maps compiler errors to specific repair strategies. Second, an Error-Stratified Transformation Strategy (ESTS) classifies compiler diagnostics into semantic error categories. Per-category temperature scheduling and stagnation detection adapt the repair behavior to balance generation diversity with constraint satisfaction. Third, a multi-stage validation pipeline ensures both compilability and functional equivalence through iterative repair. We focus on file-level transformation of self-contained C modules with standard input/output behavior, a controlled setting that isolates the core semantic mapping from C to Rust and admits differential-testing oracles for rigorous functional-equivalence checking. We evaluate AdaTrans on a dataset of 104 algorithmic problems from LeetCode Weekly Contests. We compare it with three existing LLM-based C-to-Rust tools, a zero-shot LLM baseline, and the c2rust AST-level transpiler. Across three independent runs, AdaTrans achieves a mean compilation pass rate of 95.51% ( ± \pm 1.11%) and a mean solve rate of 81.09% ( ± \pm 3.09%) under a fuzz-based test oracle, with a mean unsafe file rate of 1.19%. AdaTrans improves the solve rate over the strongest existing LLM-based tool by 59.94 percentage points. It also keeps the unsafe file rate at 1.19%, well below that of the c2rust AST-level transpiler. These results demonstrate that adapting repair strategies to the semantic characteristics of compiler diagnostics can reconcile transformation correctness with memory safety. 1. Introduction System programming languages underpin operating systems, embedded devices, and high-performance computing infrastructure. Among these languages, C has maintained its position as the de facto standard for over five decades. This enduring dominance stems from its low-level hardware control and high execution efficiency. However, the unrestrained memory access capabilities of C represent a critical weakness, which manifests as serious security vulnerabilities, including buffer overflows, null pointer dereferences, and data races. The prevalence of memory-related vulnerabilities in system software motivates the search for safer programming language alternatives. Rust has emerged as a prominent alternative to C, with widespread adoption in both academia and industry. The memory safety of Rust rests on three mechanisms: ownership, borrowing, and lifetimes. These mechanisms enforce safety checks at compile time and eliminate the majority of memory errors without sacrificing runtime performance. The transformation of codebases from C to Rust remains a challenging engineering task that traditionally demands extensive manual effort. Existing automated tools, such as c2rust ( 14 ) and Laertes ( 8 ) , generate syntactically correct Rust code that relies heavily on unsafe blocks to bypass the borrow checker. Such reliance on unsafe blocks effectively defeats the original purpose of memory safety during migration to Rust ( 5 ) . Large Language Models (LLMs), pre-trained on massive open-source codebases, have recently demonstrated potential in code generation and transformation ( 15 ; 3 ) by capturing complex syntactic structures across multiple programming languages. General-purpose LLMs, however, still face severe challenges in C-to-Rust transformation. First, the ownership rules of Rust impose a semantic barrier that general-purpose models cannot reliably cross. Generated code frequently violates borrowing and lifetime invariants because the LLM fails to map manual memory management in C to the explicit ownership model of Rust. Second, existing approaches underutilize compiler feedback for iterative repair. Rust compiler diagnostics encode rich semantic information, yet LLMs struggle to interpret complex error messages, which restricts automated repairs to superficial syntactic adjustments rather than structural corrections. Third, without targeted verification mechanisms, most generation methods prioritize syntactic correctness over functional integrity. Unsafe blocks and logical errors therefore persist in the generated code. Existing research on C-to-Rust transformation spans multiple granularities. Recent LLM-based approaches ( 42 ; 13 ; 54 ) primarily target project-level transformation, improving code idiomaticity through techniques such as skeleton-guided evolution, type-directed mutation, and pointer knowledge graphs. These advances are complementary to our work, because the central difficulty of safe transformation persists across granularities. It lies in the semantic mapping between manual memory management in C and the ownership model of Rust, where functional equivalence and memory safety must hold simultaneously. We isolate this semantic core by studying file-level transformation of self-contained C modules with standard input/output behavior. This scope is a deliberate methodological choice rather than a capability limitation. Self-contained modules admit ground-truth differential-testing oracles, making functional equivalence directly verifiable, whereas project-level migration rarely provides comparable validation mechanisms. Our repair mechanism treats each file-unit as a minimal project, so it is not bound to this granularity. The controlled setting removes confounding factors such as build configuration, cross-module dependencies, and external bindings, allowing us to focus on semantic fidelity and safety. Such units also arise naturally during incremental migration of legacy C codebases ( 19 ) , where standalone utilities and self-contained libraries are often migrated first before larger project-wide integration, while remaining straightforward to validate in isolation ( 20 ) . We assess the current state of file-level C-to-Rust transformation under this controlled setting. For this purpose, we construct a dataset of 104 algorithmic problems sourced from LeetCode Weekly Contests released after the knowledge cutoff of the LLM snapshot used in our experiments (Section 4 ). This design mitigates, but does not eliminate, the risk of benchmark contamination with respect to the evaluated model. On this dataset, a zero-shot LLM ( gpt-4o-mini ) reaches a pass@100 estimate of 70.58%. We compute this estimate from 200 independent samples per problem with the unbiased estimator of Chen et al. ( 3 ) . We use this high-budget resampling result as a strong brute-force reference under the same backbone. This reference shows that repeated independent sampling alone is still insufficient for reliable transformation. We therefore introduce AdaTrans, an end-to-end framework that transforms individual C files into predominantly safe and compilable Rust programs and preserves behavioral consistency. The key design intuition of AdaTrans is to adapt repair behavior to the type of failure signal observed during validation. Different error categories correspond to different repair needs, and a uniform strategy across heterogeneous failures is often ineffective. Syntax errors, as relatively rigid defects with narrow repair spaces, tend to benefit from low-temperature exploitation. Ownership-related errors often require moderate-temperature exploration over alternative memory-management patterns. Behavioral failures, where the program compiles but produces incorrect outputs, typically require higher-temperature exploration to escape locally consistent but semantically incorrect solutions ( 43 ; 56 ) . AdaTrans operationalizes this intuition through an error-driven repair loop that converts validation feedback into signals for retrieval and repair control (Section 3 ). The main contributions of this paper are as follows: (1) A compiler-feedback-driven framework for C-to-Rust transformation . We propose AdaTrans, a three-phase generate-verify-repair pipeline

Read the complete text