Zygo / bees

Best-Effort Extent-Same, a btrfs dedupe agent
GNU General Public License v3.0
692 stars 56 forks source link

build failure with GCC 13 #255

Open dirkmueller opened 1 year ago

dirkmueller commented 1 year ago
In member function 'void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::swap(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&) [with _Key = std::tuple<long unsigned int>; _Val = std::pair<const std::tuple<long unsigned int>, std::_List_iterator<crucible::LRUCache<crucible::Fd, long unsigned int>::Value> >; _KeyOfValue = std::_Select1st<std::pair<const std::tuple<long unsigned int>, std::_List_iterator<crucible::LRUCache<crucible::Fd, long unsigned int>::Value> > >; _Compare = std::less<std::tuple<long unsigned int> >; _Alloc = std::allocator<std::pair<const std::tuple<long unsigned int>, std::_List_iterator<crucible::LRUCache<crucible::Fd, long unsigned int>::Value> > >]',
[   13s]     inlined from 'void std::map<_Key, _Tp, _Compare, _Alloc>::swap(std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = std::tuple<long unsigned int>; _Tp = std::_List_iterator<crucible::LRUCache<crucible::Fd, long unsigned int>::Value>; _Compare = std::less<std::tuple<long unsigned int> >; _Alloc = std::allocator<std::pair<const std::tuple<long unsigned int>, std::_List_iterator<crucible::LRUCache<crucible::Fd, long unsigned int>::Value> > >]' at /usr/include/c++/13/bits/stl_map.h:1172:18,
[   13s]     inlined from 'void crucible::LRUCache<Return, Arguments>::clear() [with Return = crucible::Fd; Arguments = {long unsigned int}]' at ../include/crucible/cache.h:190:13:
[   13s] /usr/include/c++/13/bits/stl_tree.h:2092:36: error: storing the address of local variable 'new_map' in '*MEM[(struct _Rb_tree_node_base * &)&new_map + 16].std::_Rb_tree_node_base::_M_parent' [-Werror=dangling-pointer=]
[   13s]  2092 |           __t._M_root()->_M_parent = __t._M_end();
[   13s]       |           ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
[   13s] ../include/crucible/cache.h: In member function 'void crucible::LRUCache<Return, Arguments>::clear() [with Return = crucible::Fd; Arguments = {long unsigned int}]':
[   13s] ../include/crucible/cache.h:187:33: note: 'new_map' declared here
[   13s]   187 |                 decltype(m_map) new_map;
[   13s]       |                                 ^~~~~~~

this is this code:

https://github.com/Zygo/bees/blob/6ee5da7d77a46a7f70a15184307e53504f2f14ab/include/crucible/cache.h#L187-L192

apparently the compiler isn't smart enough that a .swap() operation here is sort of a safe operation. I'm saying sort of because I'm not sure the mutex actually acts as a memory barrier, and without that it would be unsafe.

ignatenkobrain commented 1 year ago

@Zygo any plans to fix this?

Zygo commented 1 year ago

I think you're just going to have to fix gcc for this one.

I can't reproduce this on Debian's g++-13 (Debian 13.1.0-1). I could reproduce two other build failures on gcc 13 and clang 16, which I've pushed fixes for.

Do you have a patch that fixes this failure? (other than CXXFLAGS += -Wno-error=dangling-pointer)