HeadlinesBriefing favicon HeadlinesBriefing.com

How Fil-C rewrites C for memory safety

Hacker News •
×

Developers have been buzzing about Fil-C, a memory‑safe variant of C/C++ that rewrites source code into a safer form. Instead of a compiler pass on LLVM IR, the simplified model inserts an AllocationRecord pointer alongside every original pointer variable. The transformation expands declarations, adds bookkeeping fields, and redirects calls to Fil‑C‑specific runtime helpers, and integrates seamlessly with existing toolchains.

Each allocation becomes three separate mallocs: one for the record, one for visible bytes and a zero‑filled buffer for invisible bytes that stores metadata about pointers stored in the heap. When a pointer is dereferenced, the compiler‑generated asserts verify that the access stays within the recorded length, using the invisible buffer to retrieve companion records for nested pointers, while preserving performance and safety guarantees overall.

The runtime also provides a garbage collector that sweeps unreachable AllocationRecord objects, freeing both visible and invisible buffers. Because the collector can reclaim memory even when free() is omitted, programmers gain leak protection while still being able to call filc_free for early release. The model even promotes escaped stack variables to heap allocations, making address‑taking safe without manual bookkeeping.