recursive structs (linked list)

It's very non-obvious, but an important lesson in how types in LLVM are
represented. In particular, in LLVM, each type shape can only exist once
in memory, which allows users to do pointer comparisons to check
structural equality of types. Naturally, this makes things interesting
when it comes to building recursive structures. :slight_smile:

The trick to it is to use an Opaque type like so:

// ST1 === struct ST1;
OpaqueType *ST1 = OpaqueType::get();

// ST2 === { int, ST1* }
StructType *ST2 = StructType::get(make_vector(Type::IntTy,
                      PointerType::get(ST1), 0));
// ST1 === ST2, delete ST1

From this point on, ST2 is the recursive struct. :slight_smile:

Sorry for the delay in the response,