<div dir="ltr">Hi all, sorry to post to both lists, but I'm running into an issue where clang-generated debug info is deemed to be invalid by LLVM tools (throws an assertion error in both llc and mcjit), and I'm not sure what the proper resolution is.<div>
<br></div><div style>Here's a test case; I last tested it on revision r210953:</div><div style><br></div><div style>$ cat test1.cpp</div><div style><div><div>#include "test.h"</div><div>test::Test<int> foo1() {</div>
<div> return test::Test<int>();</div><div>}</div></div><div><br></div><div style>$ cat test2.cpp</div><div style><div>namespace test {</div><div>}</div><div>#include "test.h"</div><div>test::Test<int> foo2() {</div>
<div> return test::Test<int>();</div><div>}</div><div><br></div><div style>$ cat test.h</div><div style><div>namespace test {</div><div>template <class T></div><div>class Test {</div><div>};</div><div>}</div>
<div style><br class="">$ clang++ -g -emit-llvm test1.cpp -S -o test1.ll</div>$ clang++ -g -emit-llvm test2.cpp -S -o test2.ll</div><div style>$ llvm-link test1.ll test2.ll -S -o linked.ll</div><div style>$ llc linked.ll</div>
<div style><br></div><div style>The last step raises an assertion error, assuming you have assertions enabled:</div><div style>llc: lib/CodeGen/AsmPrinter/DwarfUnit.cpp:953: llvm::DIE* llvm::DwarfUnit::getOrCreateTypeDIE(const llvm::MDNode*): Assertion `Ty == resolve(Ty.getRef()) && "type was not uniqued, possible ODR violation."' failed<br>
</div><div style><br></div><div style>The initial introduction of the "test" namespace in test2.cpp seems to confuse clang -- test1.cpp and test2.cpp have non-compatible debug information for the test::Test type. test1.cpp says that test::Test's namespace is defined in test.h, and test2.cpp says that test::Test's namespace is defined in test2.cpp (they both say that the class itself is defined in test.h). Regardless of whether LLVM tools should allow this, this seems like the wrong output for these files?<br>
</div><div style><br></div><div style>Another related example, is if we simply defined the test::Test template in both files (ie, manually executed the #include "test.h") and got rid of the test2.cpp "namespace test {}" definition, we'd run into the same assertion, without hitting the weird clang behavior with the empty namespace pre-declaration.</div>
<div style><br></div><div style>It's probably also worth noting that compiling directly with clang, ie adding a "int main() {}" function and then doing</div><div style>$ clang++ -g test1.cpp test2.cpp -o test</div>
<div style>works fine.</div><div style><br></div><div style>I'm not a C++ expert and I don't know if these template issues really are violations of the ODR, but it feels like this should be allowed, and somewhere in the llvm toolchain (llvm-link? DwarfUnit.cpp?) this should be handled. What do people think?</div>
<div style><br></div><div style>kmod</div></div></div></div>