<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 - std::string + -finstrument-functions + -std=c++20 = template miscompilation"
href="https://bugs.llvm.org/show_bug.cgi?id=51400">51400</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>std::string + -finstrument-functions + -std=c++20 = template miscompilation
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++2a
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mattf53190@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=25117" name="attach_25117" title="MRE and test script">attachment 25117</a> <a href="attachment.cgi?id=25117&action=edit" title="MRE and test script">[details]</a></span>
MRE and test script
When compiling with `-finstrument-functions` and any standard above C++17, that
is C++2a aka 20 or 2b aka 23, when attempting to declare a string, the proper
templates relating to standard library allocators are not included in the
object files, leading to the following linker error:
```
/usr/bin/ld: /tmp/main-6f2635.o: in function
`std::allocator_traits<std::allocator<char>
<span class="quote">>::deallocate(std::allocator<char>&, char*, unsigned long)':</span >
main.cpp:(.text._ZNSt16allocator_traitsISaIcEE10deallocateERS0_Pcm[_ZNSt16allocator_traitsISaIcEE10deallocateERS0_Pcm]+0x5d):
undefined reference to `std::allocator<char>::deallocate(char*, unsigned long)'
/usr/bin/ld:
main.cpp:(.text._ZNSt16allocator_traitsISaIcEE10deallocateERS0_Pcm[_ZNSt16allocator_traitsISaIcEE10deallocateERS0_Pcm]+0x99):
undefined reference to `std::allocator<char>::deallocate(char*, unsigned long)'
clang-14: error: linker command failed with exit code 1 (use -v to see
invocation)
```
Additionally, if the string has contents, the error will include the inability
to find an allocate method:
```
/usr/bin/ld: /tmp/main-248bd2.o: in function
`std::allocator_traits<std::allocator<char>
<span class="quote">>::deallocate(std::allocator<char>&, char*, unsigned long)':</span >
main.cpp:(.text._ZNSt16allocator_traitsISaIcEE10deallocateERS0_Pcm[_ZNSt16allocator_traitsISaIcEE10deallocateERS0_Pcm]+0x5d):
undefined reference to `std::allocator<char>::deallocate(char*, unsigned long)'
/usr/bin/ld:
main.cpp:(.text._ZNSt16allocator_traitsISaIcEE10deallocateERS0_Pcm[_ZNSt16allocator_traitsISaIcEE10deallocateERS0_Pcm]+0x99):
undefined reference to `std::allocator<char>::deallocate(char*, unsigned long)'
/usr/bin/ld: /tmp/main-248bd2.o: in function
`std::allocator_traits<std::allocator<char> >::allocate(std::allocator<char>&,
unsigned long)':
main.cpp:(.text._ZNSt16allocator_traitsISaIcEE8allocateERS0_m[_ZNSt16allocator_traitsISaIcEE8allocateERS0_m]+0x49):
undefined reference to `std::allocator<char>::allocate(unsigned long)'
/usr/bin/ld:
main.cpp:(.text._ZNSt16allocator_traitsISaIcEE8allocateERS0_m[_ZNSt16allocator_traitsISaIcEE8allocateERS0_m]+0x81):
undefined reference to `std::allocator<char>::allocate(unsigned long)'
clang-14: error: linker command failed with exit code 1 (use -v to see
invocation)
```
This manifests for `-std=c++20`, `-std=gnu++20`, `-std=c++2b`, `-std=gnu++2b`,
but not for `std=c++17`. Additionally, the g++ can compile the code with the
same flags, for every C++ standard I tested, from c++17 to c++2b.
See attached tarball for a minimal reproducible example and a script to test
whether clang++ and g++ can build it for each standard.
I wasn't sure if this qualifies as release blocker because theoretically you
could remove -finstrument-functions, in which case it compiles just fine.
However I like seeing all the function names in debugging tools like ASAN.</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>