Skip to main navigation Skip to search Skip to main content

SafeTrans: LLM-Assisted Transpilation from C to Rust

  • Stony Brook University
  • Amazon.com, Inc.
  • University of California at Davis

Research output: Chapter in Book/Report/Conference proceedingConference contributionpeer-review

1 Scopus citations

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).

Original languageEnglish
Title of host publicationProceedings - 2026 1st International Workshop on Code Translation, Transformation, and Modernization, ReCode 2026
PublisherAssociation for Computing Machinery, Inc
Pages30-37
Number of pages8
ISBN (Electronic)9798400724114
DOIs
StatePublished - Jun 1 2026
Event1st International Workshop on Code Translation, Transformation, and Modernization, ReCode 2026 - Rio de Janeiro, Brazil
Duration: Apr 12 2026Apr 18 2026

Publication series

NameProceedings - 2026 1st International Workshop on Code Translation, Transformation, and Modernization, ReCode 2026

Conference

Conference1st International Workshop on Code Translation, Transformation, and Modernization, ReCode 2026
Country/TerritoryBrazil
CityRio de Janeiro
Period04/12/2604/18/26

Keywords

  • LLM
  • Memory Safety
  • Rust
  • Transpilation
  • Vulnerability Mitigation

Fingerprint

Dive into the research topics of 'SafeTrans: LLM-Assisted Transpilation from C to Rust'. Together they form a unique fingerprint.

Cite this