<div dir="ltr">Hi, LLVM community, <div><br></div><div><div>I found an issue in my using scenario.  We deliberately parse a bitcode file twice. It contains  a named struct type. eg. <span style="color:rgb(0,0,0);font-size:medium;white-space:pre-wrap">%struct.cmd = type { float, float, float, float, float, i32 }.  In the second module->dump, %struct.cmd becomes %struct.cmd0. </span></div>
</div><div style><br></div><div style>my code is simplified like this. </div><pre class="" id="comment_text_0" style="font-size:medium;white-space:pre-wrap;width:50em;color:rgb(0,0,0)">int main()
{
    llvm::LLVMContext &llvmCtx = llvm::getGlobalContext();
    string ErrMsg;
    string filename = "wrapper.bc";
    llvm::OwningPtr<llvm::MemoryBuffer> File;

    if (llvm::MemoryBuffer::getFileOrSTDIN(filename, File)) {
        assert(0);
    }

    llvm::MemoryBuffer * buffer = File.take();
    {
        llvm::OwningPtr<llvm::Module> module(llvm::ParseBitcodeFile(buffer,
llvmCtx, &ErrMsg));
        module->dump();
    }

    {
        llvm::OwningPtr<llvm::Module> module(llvm::ParseBitcodeFile(buffer,
llvmCtx, &ErrMsg));
        module->dump();
    } </pre><div style><span style="color:rgb(0,0,0);font-size:medium;white-space:pre-wrap">}</span> </div><div style><br></div><div style><div><br></div></div><div style>with smart pointer, the 1st module will be deleted and call removeModule for the context.  The implementation of removeModule is quite simple. It just removes the PtrSet.  </div>
<div style><br></div><div style>pImpl->OwnedModules.erase(M);<br></div><div style><br></div><div style>It doesn't touch LLVMContextImpl's NamedStructTypes.  As a result, 'struct.cmd' is still in the symbol table even the module has destroyed.  In second ParseBitCodeFile, StructType::setName will introduce struct.cmd0 due to conflict.</div>
<div style><br></div><div style>should we do thorough cleanup for the method removeModule? or why does llvm retain NamedStructTypes?</div><div style><br></div><div style>thanks,</div><div style>--lx</div><div style><br></div>
</div>