CORAL introduces a novel solution for C programmers seeking improved memory safety without abandoning their familiar language. This project presents a prototype Borrow Checker, allowing for type-safe analysis while retaining the essence of C. By transforming legacy code effectively, CORAL bridges the gap between traditional programming practices and modern safety requirements.
This repository is dedicated to the implementation of the master's thesis titled CORAL: a Rust-like Borrow Checker for C, along with the accompanying paper presented at LCTES'24 titled Foundations for a Rust-Like Borrow Checker for C. The code provided here supports the experiments and findings outlined in both scholarly works.
Overview
For over 50 years, C and C++ have remained prominent programming languages, vital for maintaining legacy code and creating new software. Despite their widespread use, these languages are notorious for vulnerabilities related to memory safety. The emergence of type-safe programming languages such as Rust and Go offers promising alternatives. However, adopting a new language involves a steep learning curve and substantial effort to rewrite existing C codebases. Furthermore, many traditional C environments, particularly in embedded systems, are not yet equipped for a seamless transition to Rust due to the lack of necessary tools and libraries.
CORAL (C Ownership with Rust-like Analysis and Lifetimes) proposes a compelling solution by integrating source-to-source compilation techniques. This allows for direct analysis and transformation of existing C code, enabling effective modifications without the need to rewrite in a different language. By applying static analysis and transformations, CORAL aims to impose memory safety rules such as single ownership and strict pointer aliasing rules akin to Rust's concepts.
Key Features
- Demonstrates a proof of concept for the core ideas of the master's thesis.
- Implements a prototype Borrow Checker that applies Rust-like analysis and transformations to C.
- Enforces memory safety guarantees provided by Rust's compiler (rustc) within C codebases.
Dependencies
The project utilizes Clava as a key dependency to aid in the analysis and transformation processes.
Results
One of the primary goals of CORAL is to generate insightful and user-friendly error messages, comparable to those produced by the rustc compiler. Below is a comparison of error messages generated for a simple scenario:
rustc error message
CORAL error message
For visual reference, please refer to the following error message screenshots:
By leveraging CORAL, developers can enhance their existing C projects with improved memory safety, making this tool essential for anyone looking to modernize their C codebases while keeping them true to the original language.