SafeTrans: LLM-assisted Transpilation from C to Rust

Read full text
Authors: Muhammad Farrukh, Baris Coskun, Tapti Palit, Michalis Polychronakis
Cited by: 1
References: 45

Abstract

Rust is a strong contender for a memory-safe alternative to C as a "systems" language, but porting the vast amount of existing C code to Rust remains daunting. In this paper, we evaluate the potential of large language models (LLMs) to automate the transpilation of C code to idiomatic Rust. We present SafeTrans, a generic framework that leverages LLMs to i) transpile C code into Rust, and ii) iteratively repair compilation and runtime errors. A key novelty of our approach is a few-shot guided repair technique for translation errors, which provides contextual information and example code snippets for specific error types, guiding the LLM toward the correct solution. Another novel aspect of our work is the evaluation of the security implications of the transpilation process, showing how some vulnerability classes in C persist in the translated Rust code. SafeTrans was evaluated with six leading LLMs on 2,653 C programs and two real-world C projects. Our results show that iterative repair improves the rate of successful translations from 54% to 80% for the best-performing LLM (gpt-4o).

Fields of Study & Subjects

Security and Verification in Computing Software Testing and Debugging Techniques Logic programming and type systems

Publication details

Journal / source
Proceedings of the 1st Workshop on Code Translation, Transformation, and Modernization
Publisher
ACM
Pages
30–37
Publication date
12 April 2026
Language
EN