C2SaferRust: Transforming C Projects into Safer Rust with NeuroSymbolic Techniques
Vikram Nitin, Rahul Krishna, Luiz Lemos do Valle, Baishakhi Ray
TL;DR
The paper tackles automating the translation of large real-world C projects to Rust while preserving safety and correctness. It introduces C2SaferRust, a neuro-symbolic pipeline that starts with C2Rust to produce unsafe Rust, then decomposes the code into translation units and uses an LLM to generate safer Rust for each slice, guided by static analysis and validated via end-to-end tests. A benchmark of 7 GNU Coreutils programs plus 10 Laertes benchmarks demonstrates substantial reductions in unsafe constructs (up to 38% in raw pointers, 28% in unsafe code) and favorable comparisons to prior methods. The work provides an open-source toolkit, static-analysis components, and a methodology for safely integrating LLM-generated translations, highlighting a practical path toward safer Rust porting of large C codebases with strong empirical support.
Abstract
In recent years, there has been a lot of interest in converting C code to Rust, to benefit from the memory and thread safety guarantees of Rust. C2Rust is a rule-based system that can automatically convert C code to functionally identical Rust, but the Rust code that it produces is non-idiomatic, i.e., makes extensive use of unsafe Rust, a subset of the language that doesn't have memory or thread safety guarantees. At the other end of the spectrum are LLMs, which produce idiomatic Rust code, but these have the potential to make mistakes and are constrained in the length of code they can process. In this paper, we present C2SaferRust, a novel approach to translate C to Rust that combines the strengths of C2Rust and LLMs. We first use C2Rust to convert C code to non-idiomatic, unsafe Rust. We then decompose the unsafe Rust code into slices that can be individually translated to safer Rust by an LLM. After processing each slice, we run end-to-end test cases to verify that the code still functions as expected. We also contribute a benchmark of 7 real-world programs, translated from C to unsafe Rust using C2Rust. Each of these programs also comes with end-to-end test cases. On this benchmark, we are able to reduce the number of raw pointers by up to 38%, and reduce the amount of unsafe code by up to 28%, indicating an increase in safety. The resulting programs still pass all test cases. C2SaferRust also shows convincing gains in performance against two previous techniques for making Rust code safer.
