DIMetadata ownership model


I am wondering if there is a documentation of metadata orgranization, for example, the ownership model for the (DI)Metadata. Looks to me that you can have multiple Modules within the same LLVMContext, and that you can within a Module M2 use metadata from a Module M1 (e.g. imagine M2 is being cloned from M1, or to just use addMetadata() on a Value (let say Function from M2 by using metadata from M1)). Therefore, does this mean that LLVMContext is the owner?


That matches my understanding of the ownership model – you can’t find your way back to any Value from a DIMetadata node, so it belongs to the outermost thing in LLVM, the LLVMContext. As far as I understand it, Metadata is only freed when the LLVMContext is destroyed.

CC @StephenTozer @OCHyams who have touched LLVMContext and metadata more recently than me, in case there’s anything to add.

1 Like

@jmorse Thanks for your comment!

Yeah, exactly…