LLM4C2Rust: Large Language Models for Automated Memory-Safe Code Transpilation
Sarah Bedell, Nazanin Siavash, Armin Moin

TL;DR
This paper introduces a retrieval-augmented LLM framework for automating memory-safe C/C++ to Rust code transpilation, significantly improving correctness and security in generated code.
Contribution
It presents a novel RAG-assisted LLM approach that enhances automated code transpilation for memory safety, outperforming rule-based methods.
Findings
Achieved complete elimination of raw pointer dereferences in several programs.
Demonstrated improved code correctness and security with LLM-based transpilation.
Validated effectiveness across multiple OpenAI models.
Abstract
Memory safety has long been a critical challenge in software engineering, particularly for legacy systems written in memory-unsafe languages such as C and C++. Rust, one of the youngest modern programming languages, offers built-in memory-safety guarantees that make it a strong candidate for secure systems development. Consequently, transpiling C/C++ code into memory-safe Rust code has become a growing area of research. However, manual transpilation is often time-consuming and error-prone. Additionally, rule-based automated approaches are not as flexible or cost-effective as methods enabled by state-of-the-art AI models, techniques, and methods, such as those that deploy Large Language Models (LLMs), for example, Generative Pretrained Transformers (GPT). In this paper, we propose a Retrieval-Augmented Generation (RAG)-assisted framework that integrates an LLM with a Small Language Model…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
