Project-Level C-to-Rust Translation via Pointer Knowledge Graphs

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Yuan, Zhiqiang, Mao, Wenjun, Chen, Zhuo, Shang, Xiyue, Wang, Chong, Lou, Yiling, Peng, Xin
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866913114760413184
author Yuan, Zhiqiang
Mao, Wenjun
Chen, Zhuo
Shang, Xiyue
Wang, Chong
Lou, Yiling
Peng, Xin
author_facet Yuan, Zhiqiang
Mao, Wenjun
Chen, Zhuo
Shang, Xiyue
Wang, Chong
Lou, Yiling
Peng, Xin
contents Translating C code into safe Rust is an effective way to ensure memory safety. Compared to rule-based approaches, which often produce largely unsafe Rust code, LLM-based methods generate more idiomatic and safer Rust by leveraging extensive training on human-written code. Despite their promise, existing LLM-based approaches still struggle with project-level C-to-Rust translation. They typically partition a C project into smaller units (e.g., functions) based on call graphs and translate them in a bottom-up manner to resolve dependencies. However, this unit-by-unit paradigm often fails to handle pointers due to the lack of a global view of their usage. To address this limitation, we propose a novel C-to-Rust Pointer Knowledge Graph (KG) that augments code dependency graphs with two types of pointer semantics: (i) pointer usage information, which captures global behaviors such as points-to flows and lifts low-level struct interactions to higher-level abstractions; and (ii) Rust-oriented annotations, which encode ownership, mutability, nullability, and lifetime. Building on this KG, we further propose PtrTrans, a project-level C-to-Rust translation approach. In PtrTrans, the KG provides LLMs with comprehensive global pointer semantics, guiding them to generate safe and idiomatic Rust code. Experimental results show that PtrTrans reduces unsafe usages in translated Rust by 99.9% compared to both rule-based and conventional LLM-based methods, while achieving 29.3% higher functional correctness than fuzzing-enhanced LLM approaches.
format Preprint
id arxiv_https___arxiv_org_abs_2510_10956
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Project-Level C-to-Rust Translation via Pointer Knowledge Graphs
Yuan, Zhiqiang
Mao, Wenjun
Chen, Zhuo
Shang, Xiyue
Wang, Chong
Lou, Yiling
Peng, Xin
Software Engineering
Artificial Intelligence
Translating C code into safe Rust is an effective way to ensure memory safety. Compared to rule-based approaches, which often produce largely unsafe Rust code, LLM-based methods generate more idiomatic and safer Rust by leveraging extensive training on human-written code. Despite their promise, existing LLM-based approaches still struggle with project-level C-to-Rust translation. They typically partition a C project into smaller units (e.g., functions) based on call graphs and translate them in a bottom-up manner to resolve dependencies. However, this unit-by-unit paradigm often fails to handle pointers due to the lack of a global view of their usage. To address this limitation, we propose a novel C-to-Rust Pointer Knowledge Graph (KG) that augments code dependency graphs with two types of pointer semantics: (i) pointer usage information, which captures global behaviors such as points-to flows and lifts low-level struct interactions to higher-level abstractions; and (ii) Rust-oriented annotations, which encode ownership, mutability, nullability, and lifetime. Building on this KG, we further propose PtrTrans, a project-level C-to-Rust translation approach. In PtrTrans, the KG provides LLMs with comprehensive global pointer semantics, guiding them to generate safe and idiomatic Rust code. Experimental results show that PtrTrans reduces unsafe usages in translated Rust by 99.9% compared to both rule-based and conventional LLM-based methods, while achieving 29.3% higher functional correctness than fuzzing-enhanced LLM approaches.
title Project-Level C-to-Rust Translation via Pointer Knowledge Graphs
topic Software Engineering
Artificial Intelligence
url https://arxiv.org/abs/2510.10956