Find your next open-source project

Search by name, purpose, or keyword, or paste a GitHub URL. Start with / to search agent skills (e.g. /pdf)

safe-c-project/safe-c

Developer Tools

Forked from cs01/llvm-project, originally from llvm/llvm-project

A Clang-based compiler that enforces Rust-like memory safety in C and C++ through annotations and a restricted subset.

191
8
LLVM
NOASSERTION
4 days old
+90 stars in 13h

What it does

Safe C and Safe C++ are two compiler modes in a fork of Clang that aim to give C and C++ the same memory-safety guarantees as safe Rust: no use after free, double free, out-of-bounds access, null dereference or data race. Code that cannot be proven safe either fails to compile or traps at run time before memory is corrupted.

The two languages take different routes. Safe C (safecc, -fsafe-c) adds ownership and borrow annotations such as _Owned, _Take, _Static, _Nullable and __counted_by, which are macros that compile to nothing under other compilers. Safe C++ (safec++, -fsafe-cxx) adds no keywords; instead it restricts code to a safe subset of standard C++ (no new/delete, no pointer arithmetic, no unions) and uses libc++ hardening for bounds checks. See the safety guarantees and the annotation reference.

It targets teams with existing C or C++ code who want to keep the language and ABI while catching memory bugs at compile time, rather than rewriting in Rust or adopting a runtime checker.

Quick start

To try it without installing, the browser playground runs the compiler in WebAssembly and shows each example built with -fsafe-c or -fsafe-cxx alongside plain C/C++.

On macOS, install via Homebrew and compile a file:

brew install safe-c-project/tap/safe-c
safecc file.c
safec++ file.cpp

Release packages exist for macOS arm64 and Linux x86_64; building from source is covered in the building guide. Building Safe C++ programs needs libc++, the macOS default or -stdlib=libc++ on Linux. A check-only pass is possible anywhere with safecc -fsyntax-only file.c or safec++ -fsyntax-only file.cpp, which enforces ownership, borrow, null and race rules without producing a binary.

Adoption and constraints

Safe C is applied per file: annotated files link with plain C files because the ABI is unchanged. The project suggests running check-only mode in CI first and keeping existing compilers for normal builds. Annotations split into Clang's own (_Nullable, __counted_by, thread-safety attributes) and Safe C-specific ones read only by this compiler; the latter may change or the project may stop, so they are the main migration risk. Code not yet ready can be wrapped in __unsafe { } or a header marked with #pragma clang safe_c legacy. Safe C++ is a subset of standard C++, so passing files still build with any C++ compiler.

Common unsafe libc functions (gets, strcpy, sprintf, rand, and many more) are rejected outright. I/O and other calls into C libraries are only as safe as their contracts in safe-c-types, which the compiler trusts. Ownership checking roughly doubles C compile time (1.3x–2.1x), while Safe C++ adds 3%–10%. Runtime cost concentrates in bounds checks that cannot be proven away; the README reports zlib inflate at 0.96x–0.99x and stb_image at 0.67x of plain C's speed on macOS arm64. Licensing is Apache 2.0 with LLVM Exceptions.

Status and limits

Both compilers are described as ready for testing but unused in production, and the project is explicitly asking people to try them on real code. Safe C's language is frozen; Safe C++ is still an opinionated subset. Guarantees cover the listed bug classes, not the safety of called library code; the README describes the safety rules as proven sound in small Lean models, while the compiler's enforcement is tested rather than proved, the same situation as Rust and RustBelt.

HotRepo's take

The 2026-12-03 new-project snapshot recorded 114 stars and 13 stars gained over a roughly 1.5-hour window, for 6 forks. That is early traction for a compiler project, consistent with a launch-stage tool that has not yet accumulated external users. The interesting technical claim is not the star count but the strategy: compile-time ownership checks with an unchanged ABI, in contrast to the runtime approach of Fil-C, and a documented comparison against Rust and Fil-C. Whether the safety guarantees hold on real codebases remains to be tested by outside users, which is exactly what the project is asking for.

Written by AI from the project's public information and HotRepo's records, updated . The project's own docs are the source of truth.

You might also like

  1. aardappel/gooseA memory-safe systems language with no heap, GC or lifetime annotations, compiling to C.C++2,570
  2. vercel-labs/scriptcCompiles a subset of TypeScript and JavaScript into standalone native executables or WebAssembly, without requiring Node.js at runtime.TypeScript6,474
  3. clice-io/cliceA Clang-based C, C++, Objective-C and CUDA language server with isolated worker processes, C++20 module support and a project-wide CLI.C++1,749
  4. rust-lang/rustThe Rust compiler, standard library, and documentation source, for developers building or contributing to Rust.Rust121,159
  5. rauchg/xeetRender X posts to pixel-accurate PNGs without a browser, in Rust and WebAssembly.JavaScript105