Raw Pointer Rewriting with LLMs for Translating C to Safer Rust
Yifei Gao, Chengpeng Wang, Pengxiang Huang, Xuwei Liu, Mingwei Zheng, and Xiangyu Zhang

TL;DR
This paper presents PR2, a technique that rewrites raw pointers in C-to-Rust translation to improve safety, using decision-tree prompting and code analysis, successfully eliminating 18.57% of raw pointers in real projects.
Contribution
PR2 introduces a novel raw pointer rewriting method that lifts raw pointers to safer Rust structures, enhancing translation safety from C to Rust.
Findings
PR2 eliminates 18.57% of local raw pointers in real-world C projects.
PR2 completes transformations in about 5 hours per project at a cost of $1.13.
PR2 effectively guides pointer lifting and error repair during translation.
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, PR2 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…
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.
