[llvm-bugs] [Bug 47418] New: Destructor not called when returning object from template class method
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Sep 4 07:23:34 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47418
Bug ID: 47418
Summary: Destructor not called when returning object from
template class method
Product: clang
Version: 10.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: tavplubix at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Created attachment 23928
--> https://bugs.llvm.org/attachment.cgi?id=23928&action=edit
minimized code to reproduce a bug, version 2
LeakSanitizer and valgrind report a strange memory leak when building the
following code with clang. No leaks are found when building it with gcc. Seems
like it's a bug in clang and some destructor is not called.
Original code: https://github.com/ClickHouse/ClickHouse/pull/14295
See attached file with minimized code.
How to reproduce:
$ clang++-10 -v
clang version 10.0.0-4ubuntu1~18.04.2
Target: x86_64-pc-linux-gnu
...
$ clang++-10 -std=c++17 -fsanitize=address minimized2.cpp
$ ./a.out
0
ctor 7ffe1e6d8920
copy 603000000010
move 603000000040
dtor 603000000010
dtor 7ffe1e6d8920
dtor 603000000040
1
ctor 7ffe1e6d8920
copy 603000000070
move 6030000000a0
dtor 7ffe1e6d8920
dtor 6030000000a0
2
ctor 7ffe1e6d8920
copy 6030000000d0
move 603000000100
dtor 6030000000d0
dtor 7ffe1e6d8920
dtor 603000000100
3
=================================================================
==3408==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 32 byte(s) in 1 object(s) allocated from:
#0 0x4c43dd in operator new(unsigned long)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c43dd)
#1 0x4ca50b in __gnu_cxx::new_allocator<Elem>::allocate(unsigned long, void
const*) (/home/avtokmakov/ch/llvm-bugreport/a.out+0x4ca50b)
#2 0x4ca4b3 in std::allocator_traits<std::allocator<Elem>
>::allocate(std::allocator<Elem>&, unsigned long)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4ca4b3)
#3 0x4ca3f2 in std::_Vector_base<Elem, std::allocator<Elem>
>::_M_allocate(unsigned long)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4ca3f2)
#4 0x4c9e6f in void std::vector<Elem, std::allocator<Elem>
>::_M_range_initialize<Elem const*>(Elem const*, Elem const*,
std::forward_iterator_tag) (/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c9e6f)
#5 0x4c7f09 in std::vector<Elem, std::allocator<Elem>
>::vector(std::initializer_list<Elem>, std::allocator<Elem> const&)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c7f09)
#6 0x4ccb51 in TableFunctionTemplate<false>::getActualTableStructure()
const (/home/avtokmakov/ch/llvm-bugreport/a.out+0x4ccb51)
#7 0x4c7028 in main (/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c7028)
#8 0x7f4eae5d5b96 in __libc_start_main
/build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
Indirect leak of 42 byte(s) in 1 object(s) allocated from:
#0 0x4c43dd in operator new(unsigned long)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c43dd)
#1 0x4c949b in __gnu_cxx::new_allocator<char>::allocate(unsigned long, void
const*) (/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c949b)
#2 0x4c93e3 in std::allocator_traits<std::allocator<char>
>::allocate(std::allocator<char>&, unsigned long)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c93e3)
#3 0x4c8ffb in std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::_M_create(unsigned long&, unsigned long)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c8ffb)
#4 0x4c8a53 in void std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char
const*, char const*, std::forward_iterator_tag)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c8a53)
#5 0x4c884b in void std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >::_M_construct_aux<char
const*>(char const*, char const*, std::__false_type)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c884b)
#6 0x4c85f4 in void std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char
const*, char const*) (/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c85f4)
#7 0x4c8475 in std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::basic_string<std::allocator<char> >(char const*,
std::allocator<char> const&)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c8475)
#8 0x4ca819 in Print::Print(Print const&)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4ca819)
#9 0x4ca6fc in Elem::Elem(Elem const&)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4ca6fc)
#10 0x4ca67c in void std::_Construct<Elem, Elem const&>(Elem*, Elem const&)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4ca67c)
#11 0x4ca5ae in Elem* std::__uninitialized_copy<false>::__uninit_copy<Elem
const*, Elem*>(Elem const*, Elem const*, Elem*)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4ca5ae)
#12 0x4ca568 in Elem* std::uninitialized_copy<Elem const*, Elem*>(Elem
const*, Elem const*, Elem*) (/home/avtokmakov/ch/llvm-bugreport/a.out+0x4ca568)
#13 0x4ca448 in Elem* std::__uninitialized_copy_a<Elem const*, Elem*,
Elem>(Elem const*, Elem const*, Elem*, std::allocator<Elem>&)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4ca448)
#14 0x4c9f76 in void std::vector<Elem, std::allocator<Elem>
>::_M_range_initialize<Elem const*>(Elem const*, Elem const*,
std::forward_iterator_tag) (/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c9f76)
#15 0x4c7f09 in std::vector<Elem, std::allocator<Elem>
>::vector(std::initializer_list<Elem>, std::allocator<Elem> const&)
(/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c7f09)
#16 0x4ccb51 in TableFunctionTemplate<false>::getActualTableStructure()
const (/home/avtokmakov/ch/llvm-bugreport/a.out+0x4ccb51)
#17 0x4c7028 in main (/home/avtokmakov/ch/llvm-bugreport/a.out+0x4c7028)
#18 0x7f4eae5d5b96 in __libc_start_main
/build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
SUMMARY: AddressSanitizer: 74 byte(s) leaked in 2 allocation(s).
As you can see from the output, destructor for 603000000070 is not called in
the second case (when calling tf2.getActualTableStructure()).
Also it reproduces with clang 9 and clang trunk: https://godbolt.org/z/491eG3
--
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/20200904/21364405/attachment.html>
More information about the llvm-bugs
mailing list