[LLVMdev] named types with self-references

Chris Lattner clattner at apple.com
Thu Nov 11 09:11:21 PST 2010


On Nov 11, 2010, at 8:45 AM, Jianzhou Zhao wrote:

> Hello,
> 
> Can I define a named type ?   %rt = {%rt}
> llvm-as can parse this definition without errors.
> 
> JIT executes '%0 = alloca %rt' as allocating a memory with size 0.
> Because the llvm::TargetData::getTypeAllocSize accually returns 0 in
> this case. The function that calculates %rt's size is by the
> TargetData::getStructLayout, which calculates the a layout of %rt. It
> can only returns 0 when the element type %rt is not defined yet, since
> the result is infinite otherwise.
> 
> Is %rt = {%rt} still a valid or useful type for LLVM IR?

No, that's not (or shouldn't be) a valid type.  In this case, zero bytes is correct, but something like %rt = {%rt,i8} has infinite size.

-Chris



More information about the llvm-dev mailing list