Fil-C is a memory-safe implementation of C/C++ that works by transforming unsafe code into safe code. The core mechanism pairs every pointer variable with an accompanying AllocationRecord* that tracks the allocation's visible bytes, invisible bytes (for storing pointer metadata in heap allocations), and length. Pointer dereferences trigger bounds checks against the AllocationRecord. Heap-allocated pointers store their accompanying AllocationRecord* in a parallel 'invisible_bytes' array. A garbage collector handles AllocationRecord lifetime, meaning forgotten free() calls no longer cause leaks. The transform also promotes stack variables whose addresses escape to heap allocations. Production complications include thread safety, function pointer type verification, and performance optimizations. Use cases include auditing existing C/C++ codebases for memory bugs, safe compile-time evaluation in languages like Zig, and as a concrete model for studying pointer provenance.

7m read timeFrom corsix.org
Post cover image

Sort: