[llvm-bugs] [Bug 51400] New: std::string + -finstrument-functions + -std=c++20 = template miscompilation

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Aug 7 07:16:17 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51400

            Bug ID: 51400
           Summary: std::string + -finstrument-functions + -std=c++20 =
                    template miscompilation
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mattf53190 at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Created attachment 25117
  --> https://bugs.llvm.org/attachment.cgi?id=25117&action=edit
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>
>::deallocate(std::allocator<char>&, char*, unsigned long)':
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>
>::deallocate(std::allocator<char>&, char*, unsigned long)':
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210807/8639d0fb/attachment.html>


More information about the llvm-bugs mailing list