<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - [codeview] Explicit template specializations can have wrong inline line information"
href="https://bugs.llvm.org/show_bug.cgi?id=49119">49119</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[codeview] Explicit template specializations can have wrong inline line information
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rnk@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>This is similar to llvm.org/pr48432, but it's a corner case that deserves its
own bug. Consider this program:
$ cat -n t.cpp
1 #include <stdio.h>
2 volatile int gv;
3 template <typename T> void foo() { gv += sizeof(T); }
4 // not here
5 // not here
6
7 template <> void foo<void>() {
8 gv += 1;
9 __debugbreak();
10 }
11 int main() {
12 puts("asdf");
13 foo<short>();
14 foo<void>();
15 foo<int>();
16 puts("asdf");
17 }
Compiled like so:
$ clang-cl -Z7 -O2 t.cpp
If you load it in windbg and run to the breakpoint, it stops on line 5, which
is not in any function. See the stack trace:
0:000> k
# Child-SP RetAddr Call Site
00 (Inline Function) --------`-------- t!foo+0xa
[C:\src\llvm-project\build\t.cpp @ 5]
01 00000069`8deffda0 00007ff6`de54965c t!main+0x28
[C:\src\llvm-project\build\t.cpp @ 14]
...
The line is wrong, we should be stopped on line 9. As was the case in issue
48432, the problem is that the LF_FUNC_ID records for the specialization of foo
and the foo template are identical. The linker merges identical LF_FUNC_ID
records, and the LF_FUNC_ID index is used as a key in a map which maps from
function id to the starting line number of the function.
However, MSVC has the same bug! If you follow the same steps, the debugger
stops on line 4, but is otherwise no different:
$ cl -O2 -Z7 t.cpp
... windbg...
0:000> k
# Child-SP RetAddr Call Site
00 (Inline Function) --------`-------- t!foo+0xe
[C:\src\llvm-project\build\t.cpp @ 4]
01 000000ae`507df750 00007ff7`28d56fb0 t!main+0x2d
[C:\src\llvm-project\build\t.cpp @ 14]
So, this is a bit of a corner case bug, and it may not be worth fixing. If we
want to fix the bug, we would need to find a way to make the names of template
specializations uniquely different from template instantiations. Right now we
remove all template arguments here:
<a href="https://github.com/llvm/llvm-project/blob/e090182fe153c9ceea50b1807f8ca5c13729e402/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp#L361">https://github.com/llvm/llvm-project/blob/e090182fe153c9ceea50b1807f8ca5c13729e402/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp#L361</a>
We do this to match MSVC, but if we adjust that logic, we could have unique
names and the inlinee line map would work again.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>