C2RUST-BENCH: A Minimized, Representative Dataset for C-to-Rust Transpilation Evaluation

Melih Sirlanci, Carter Yagemann, Zhiqiang LinarXiv 2025 · DOI

Abstract

Evaluating C-to-Rust transpilation tools often requires choosing between small, unrepresentative datasets and massive, computationally expensive ones. We present C2Rust-Bench, a curated dataset of 2,905 functions derived from over 15,000 real-world samples. By employing a multi-metric sampling strategy, we reduce evaluation time by nearly 80% while maintaining the complexity and difficulty profile of the original source. Our results demonstrate that C2Rust-Bench generalizes across multiple Large Language Models (LLMs), providing a rigorous and efficient benchmark for modern transpilation research.

Introduction

Memory safety vulnerabilities, such as buffer overflows, account for approximately 70% of security flaws in modern software. While the industry is pivoting toward memory-safe languages like Rust, the manual conversion of legacy C codebases is a Herculean task. Automated transpilation, particularly using Large Language Models (LLMs), offers a promising solution. However, evaluating these tools presents a "Goldilocks problem": small datasets lack the edge cases necessary for rigorous testing, while large datasets (exceeding 15,000 functions) are prohibitively slow and expensive to process via LLM APIs.

C2Rust-Bench addresses this gap by providing a minimized yet representative dataset that captures the full spectrum of transpilation challenges in a fraction of the size.

Methodology

The researchers developed a multi-stage pipeline to distill a massive collection of C functions into a lean benchmark:

  1. Metric Definition: Code complexity was quantified using four key metrics, including the Maintainability Index (MI), Unsafe Code Complexity (counting unsafe blocks in the resulting Rust), and Data Type Complexity.
  2. Transpilation Loop: To generate Rust-side metrics, the team utilized Qwen2.5-coder:32b for initial transpilation. An automated "fixing loop" incorporated compiler feedback to refine the output.
  3. Partitioning & Sampling: The metrics formed a 4D space divided into "bins." To ensure the benchmark included both "average" and "extreme" cases, the authors used Principal Component Analysis (PCA) to rank and systematically sample functions within each bin.

Dataset Composition

The study utilized three distinct sets:

  • The Large Set: 15,503 functions harvested from 65 real-world C programs (e.g., libxml2, tmux, wget, and tar).
  • Microbenchmark Set: A ~10% random sample (1,573 functions) used for initial LLM evaluation and selection.
  • C2Rust-Bench: The final curated set of 2,905 functions, representing an 81.3% reduction in function count and a 74.4% reduction in Source Lines of Code (SLoC) compared to the original pool.

Key Results and Generalization

The primary achievement of C2Rust-Bench is its efficiency. Evaluating a transpiler on the full dataset required 246 hours, whereas C2Rust-Bench reduced this to just 52 hours—a nearly 80% time saving.

Diversity and Difficulty Preservation

A critical requirement for a minimized benchmark is that it must not "cherry-pick" easy cases. The authors demonstrated through error-distribution analysis that the subset maintains the same difficulty profile as the massive original dataset. As shown in Figure 3, the distribution of compilation error fixing attempts for the selected functions closely mirrors that of the larger microbenchmark set.

Distribution of compilation error fixing attempts, showing that the selected functions maintain the difficulty profile of the larger set.

Cross-LLM Generalization

A crucial finding was that a dataset curated using one specific model (Qwen) remains representative when evaluating other LLMs like Llama or Mistral. Figure 1 illustrates the relative performance differences across nine different models, confirming that the benchmark is not biased toward the model used for its creation.

Relative difference in performance across various LLMs, demonstrating the benchmark's generalizability.

In head-to-head comparisons, Qwen2.5-coder:32b emerged as the leader with a 97.6% transpilation success rate, followed closely by Qwen2.5-coder:14b at 96.2%.

Conclusion

C2Rust-Bench demonstrates that complexity in transpilation is not merely a function of code length but of the combination of constructs like pointers and complex data types. While the current benchmark focuses on function-level isolation, it provides a robust foundation for future work in project-level transpilation and automated error correction. By significantly lowering the barrier to entry for rigorous evaluation, C2Rust-Bench accelerates the development of safer software migration tools.

Summary updated

BibTeX
@misc{sirlanci2025c,
  author = {Melih Sirlanci and Carter Yagemann and Zhiqiang Lin},
  title = {{C2RUST-BENCH: A Minimized, Representative Dataset for C-to-Rust Transpilation Evaluation}},
  year = {2025},
  eprint = {2504.15144},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.15144},
}
Figure