Saved in:
Bibliographic Details
Main Authors: Farrukh, Muhammad, Coskun, Baris, Palit, Tapti, Polychronakis, Michalis
Format: Preprint
Published: 2025
Subjects:
Online Access:https://arxiv.org/abs/2505.10708
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866908987560034304
author Farrukh, Muhammad
Coskun, Baris
Palit, Tapti
Polychronakis, Michalis
author_facet Farrukh, Muhammad
Coskun, Baris
Palit, Tapti
Polychronakis, Michalis
contents 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).
format Preprint
id arxiv_https___arxiv_org_abs_2505_10708
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle SafeTrans: LLM-assisted Transpilation from C to Rust
Farrukh, Muhammad
Coskun, Baris
Palit, Tapti
Polychronakis, Michalis
Cryptography and Security
Software Engineering
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).
title SafeTrans: LLM-assisted Transpilation from C to Rust
topic Cryptography and Security
Software Engineering
url https://arxiv.org/abs/2505.10708