Fil-C

Memory SafetyC/C++ CompatibilityModern Tooling

Fil's Unbelievable C Compiler

Fil-C is a fork of clang 20.1.8 that includes:

The FilPizlonator

This pass applies memory safety rules to every single construct in LLVM IR, including:

FilPizlonator will turn code into an always-panic if it doesn't know how to check it. If the code is particularly evil, FilPizlonator will simply crash and refuse to compile.

FilPizlonator also has extensive support for accurate GC, including:

FilPizlonator started out as a zero-optimizations, instrument-everything-with-function-calls style, since I wasn't even sure if the technique would conceptually work out. Since it did work out, many optimizations have been added:

Clang CodeGen Changes

Clang's CodeGen module lowers the AST (abstract syntax tree) into LLVM IR. The AST still contains C/C++ types, while LLVM IR uses a lower-level type system. A key insight of Fil-C is that clang CodeGen is mostly well-behaved with respect to pointers. Values that would have been thought of as having pointer type by the C or C++ programmer (so any * pointer or & reference, as well as any struct or class that contains pointers) are lowered to LLVM IR that uses the ptr type.

There are two major exceptions to this property of CodeGen, and to make Fil-C work, surgical changes had to be made to make CodeGen completely preserve pointer intent:

Clang Driver

GCC and compatible compilers like clang have a driver process that takes command-line arguments from the user and transforms them into internal command-line arguments taken by the actual compiler process. The driver's responsibilities include:

Every operating system has opinions about these things, and the clang driver knows about the opinions of every operating system supported by clang.

Fil-C has its own opinions, which vary a bit depending on how the Fil-C compiler and runtime are distributed. Some things that are common across distributions:

The clang driver contains changes to link these additional libraries and object files, as necessary.

Finally, depending on what kind of Fil-C distribution you are using, the driver takes different paths for working out the header file and library locations:

The Fil-C Pass Pipeline

Below is a graphic showing the Fil-C pass pipeline.

Fil-C pass pipeline

Fil-C reuses the LLVM pass pipeline after FilPizlonator, and also runs a mini version of that pipeline before FilPizlonator. The pre-pizlonating passes achieve: