[LLVMdev] named types with self-references
Chris Lattner
clattner at apple.com
Thu Nov 11 09:54:47 PST 2010
On Nov 11, 2010, at 9:37 AM, Jianzhou Zhao wrote:
> On Thu, Nov 11, 2010 at 12:11 PM, Chris Lattner <clattner at apple.com> wrote:
>>
>> 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.
>
> I tried %rt = {%rt,i8}, Its type size is 1. Does ' infinite size' mean
> the getTypeAllocSize function may not terminate? I am still using
> 2.6, whose getStructLayout stops, and assigns 1 as StructSize. Will
> 2.8 return a larger number?
I'm sure that TargetData doesn't handle it, because it doesn't make sense. This is equivalent to defining this type in C:
struct foo {
struct foo a;
char b;
};
-Chris
More information about the llvm-dev
mailing list