<div>Hi, </div><div>I filled a bug report here, although it might be working as designed: <a href="http://llvm.org/bugs/show_bug.cgi?id=14609">http://llvm.org/bugs/show_bug.cgi?id=14609</a></div><div><br></div><div>Description:</div>

<div><div>The LinkModules.cpp link implementation assumes the 2 modules were built with a</div><div>completely different context.</div><div><br></div><div>To map a type from module B into module A it relies in the fact that when</div>

<div>merging contexts all structs in module B named like any in module A got renamed</div><div>to name.NUMBER, like struct_name.1</div><div><br></div><div>In my use case in the same compiler run, I create module A and while creating</div>

<div>module B I take types from module A like module_a->getTypeByName("struct_name")</div><div><br></div><div>This causes that when I link both modules as struct_name was never requested in</div><div>module B context it didn't participate in the merging, it was already there,</div>

<div>and because of that there is no struct_name.1</div><div>When LinkModules iterates structs on module A and module B it does not detect</div><div>the type to be mapped so it does not intrudce it in the TypeMap and on later</div>

<div>resolution the Linker creates a whole new named struct type and injects it</div><div>there.</div><div><br></div><div>I have assumed that 2 StructTypes with the same name and the same address are</div><div>the same type so I have created this patch that adds it into the TypeMap and</div>

<div>type mapping works as expected, adding it to the TypeMap will check isomorphism</div><div>as well so there is no apparent risk.</div><div><br></div><div>Before the patch I used to get types as:</div><div>%0 = type { i8*, i8* }</div>

<div>%core_string = type { i8*, i8* }</div><div><br></div><div>in the linked file, if I dumped the modules and used llvm-link it would work</div><div>perfectly because it would load each file in a different context.</div>

<div><br></div><div>With the patch I get the same result as using llvm-link on the separated</div><div>modules.</div><div>%core_string = type { i8*, i8* }</div><div><br></div><div><br></div><div><br></div><div>It could well be that this was always intended, but then the only alternative I</div>

<div>see in this case to steal struct types from the first module is to do deep</div><div>copies of them, and I haven't seen any helper methods for that in any case.</div></div><div><br>--<br>Arkaitz</div><br>