Commit 2d53565
Zygo Blaxell
progress: work around GCC-16 -Warray-bounds bug
`make_shared<ProgressTrackerState>()` keeps triggering GCC bugs.
The latest failure on GCC-16.0 and GCC-16.1:
/usr/include/c++/16.1.1/bits/stl_tree.h:1383:19: error: array subscript 1 is outside array bounds of ‘std::_Sp_counted_ptr_inplace<crucible::ProgressTracker<long unsigned int>::ProgressHolderState, std::allocator<void>, __gnu_cxx::_S_atomic> [1]’ [-Werror=array-bounds=]
../include/crucible/progress.h:46:24: error: array subscript ‘crucible::ProgressTracker<long unsigned int>::ProgressTrackerState[0]’ is partly outside array bounds of ‘unsigned char [40]’ [-Werror=array-bounds=]
The regression is already reported to the GCC project:
https://www.mail-archive.com/gcc-bugs%40gcc.gnu.org/msg895281.html
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123912
(and its duplicates)
The problem is that GCC's static analyzer forgets that make_shared
intentionally allocated a control block and an object in the same
allocation, and thinks that accesses beyond the end of the control block
are out-of-bounds array accesses.
This workaround is the shortest: start with a unique_ptr (which has no
control block but does have an exception-safe allocator), then convert
to shared_ptr. This breaks the allocation into two parts so that GCC
is no longer confused. As there are typically fewer than 10k progress
tracking items, the separate control blocks will only add a few hundred
KiB of RAM usage.
Signed-off-by: Zygo Blaxell <bees@furryterror.org>1 parent 3812e3d commit 2d53565
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
0 commit comments