[LLVMdev] infinitely recursive named struct types

Chris Lattner clattner at apple.com
Thu Oct 6 10:50:45 PDT 2011


On Oct 5, 2011, at 4:58 AM, Török Edwin wrote:

> Hi,
> 
> Looks like it is possible to create an infinitely recursive struct type, llvm-as accepts this:
> %s = type { i32, i8, %s }

This should be illegal, and should probably be caught by the verifier.

-Chris

> 
> define %s @foo(%s* %a) {
>    %y = load %s* %a
>    ret %s %y
> }
> 
> %s2 = type { i32, %s3}
> %s3 = type { i8, %s2}
> 
> declare %s3 @foo2();
> 
> Similarly it is doable via the API: create a named struct, create elements where one refers directly to the
> newly created struct (instead of pointer), and then setbody.
> 
> I can't see how such a type can be useful (I created it by accident, meant to use pointer-to struct,
> not struct type directly), and in fact llvm-dis crashes on bitcodes with infinetely recursive struct types.
> 
> I'd suggest that such infinetely (mutually-)recursive struct types should be rejected on creation,
> at least via an assert.
> 
> FWIW llvm-as itself crashes on this:
> %s = type { i32, i8, %s }
> define void @foo() {
>    %x = alloca %s
>    ret void
> }
> 
> Best regards,
> --Edwin
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev





More information about the llvm-dev mailing list