Keywords: Rust, Program Transformation, Program Repair, Large Language Model
Abstract: There has been a growing interest in translating C code to Rust due to Rust's robust memory and thread safety guarantees. Tools such as $C2Rust$ enable syntax-guided transpilation from C to semantically equivalent Rust code. However, the resulting Rust programs often rely heavily on unsafe constructs, particularly raw pointers, which undermines Rust’s safety guarantees.
This paper aims to improve the memory safety of Rust programs generated by $C2Rust$ by eliminating raw pointers. Specifically, we propose a raw pointer rewriting technique that lifts raw pointers in individual functions to appropriate Rust data structures. Technically, $PR^2$ employs decision-tree-based prompting to guide the pointer lifting process. It also leverages code change analysis to guide the repair of errors introduced during rewriting, effectively addressing errors encountered during compilation and test case execution.
We implement $PR^2$ as a prototype and evaluate it using gpt-4o-mini on 28 real-world C projects. The results show that $PR^2$ successfully eliminates 18.57\% of local raw pointers across these projects, significantly enhancing the safety of the translated Rust code. On average, $PR^2$ completes the transformation of a project in 5.02 hours, at an average cost of \$1.13.
Paper Type: Long
Research Area: NLP Applications
Research Area Keywords: NLP Applications
Contribution Types: NLP engineering experiment, Publicly available software and/or pre-trained models
Languages Studied: English
Submission Number: 2910
Loading