How to access a structured array of unsized type

First, I customize a data structure:

typedef struct{
    char name[10];
    void* fp;
} test;

I created this data structure during the IR phase.

static StructType* Test_Type = llvm::StructType::create(C,"test");

Also, I create a structured array:

test my_test[10];
test* my_test_pointer = my_test;

Finally, I tried to access its elements through getelementptr and got the following error:

GEP into unsized type!
  %1 = getelementptr %test, %test* %0, i32 0

What is the cause of this unsized Type? How do I resolve this error?
Any answer would be of great help to me. Thanks.

You need to call StructType::setBody to tell LLVM about the struct contents, it can’t see any definition you might have in a header and cross-reference with the “test” name you gave.

You can also use one of the other create methods that takes a list of members at the same time rather than having to create and then set the body (only needed when you have a cycle).