Insert a new struct declaration

Hi,
I want to insert a struct declaration which is defined in b.bc into a.bc, so that I use that struct in a.bc after I link a.bc and b.bc. And I also want to find that declaration in a.ll.
How can i do that ? I only find how to insert function’s declaration.

Types really belong to the LLVMContext and are only printed with the Module if they’re used. So provided your two modules are loaded into the same context you can just start using the type from one and everything should work.

To look up a type you can use StructType::getTypeByName (assuming it’s named, if it’s not then you must already know its full structure and can just create it again). But if there’s a name clash, for example when linking modules together, LLVM will just rename one so it’s not a truly reliable way to track things (just a hint for debugging IR really).

Thank for your reply!
It works. However, which I insert is different from origin (get them via .ll program).
For example, this is mine: %ff = type { float, float }, the origin is %struct.ff = type { float, float }.
Do they function the same?It makes me confused.

They’ll function identically, though you might need to insert bitcast instructions if you end up with the wrong type at any point.

When you create your version of the struct you can probably call it “struct.ff” to avoid even that.

Thank you!
Though I have found they are identical via experiment,I am confused.
So the %struct.ff is just a name of structure, and it has any special meaning?(I used to think it had a special meaning, )
If that‘s right, I can call it as same as another, and it will facilitate my work!