-
Notifications
You must be signed in to change notification settings - Fork 350
Array bounds warning when compiling with gcc11 #153
Description
We're trying to track down the source of a warning that we are required to silence for the R package s2 (in order to keep the package on CRAN). A new test has been added to the CRAN servers with the development version of gcc (i.e., gcc11). Compiling the s2 package gives new warnings with -Warray-bounds in s2/util/gtl/btree.h, and nether myself nor @edzer have the expertise to know if these errors are (1) a bug in gcc11, (2) real but not important, or (3) an actual out-of-bounds array error. There is an issue thread of our struggles with this here: r-spatial/s2#79
I've put together a reprex to illustrate the problem...unfortunately it involves building gcc11 from source (which is what CRAN has done). The gist version is here: https://gist.github.com/paleolimbot/51db5e587b5f3e57a637b6a24655fe87
Note that all of
- gcc11/devel
map[4] = 4;(i.e., insertion)-DNDEBUGand-O2
...are necessary to reproduce.
git clone https://gist.github.com/51db5e587b5f3e57a637b6a24655fe87.git gcc11-gtl-btree
cd gcc11-gtl-btree
# this takes several hours
docker build . --tag r-gcc11
docker run --rm r-gcc11 g++ --versiong++ (GCC) 11.0.0 20201024 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# with latest github s2
curl -L https://github.com/google/s2geometry/archive/master.zip --output s2.zip
unzip s2.zip
docker run --rm -v $(pwd):/test -w /test r-gcc11 g++ -std=c++11 -I s2geometry-master/src -O2 -DNDEBUG -Warray-bounds test.cpp -o testIn file included from s2geometry-master/src/s2/util/gtl/btree_map.h:34,
from test.cpp:3:
s2geometry-master/src/s2/util/gtl/btree.h: In function ‘int main()’:
s2geometry-master/src/s2/util/gtl/btree.h:604:22: warning: array subscript [33, 287] is outside array bounds of ‘absl::container_internal::Allocate<8, std::allocator<std::pair<int* const, std::pair<int, bool> > > >::M [32]’ [-Warray-bounds]
604 | mutable_child(i) = c;
| ~~~~~~~~~~~~~~~~~^~~
In file included from /usr/local/include/c++/11.0.0/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
from /usr/local/include/c++/11.0.0/bits/allocator.h:46,
from /usr/local/include/c++/11.0.0/memory:64,
from s2geometry-master/src/s2/util/gtl/btree_map.h:30,
from test.cpp:3:
/usr/local/include/c++/11.0.0/ext/new_allocator.h:121:48: note: referencing an object of size between 48 and 256 allocated by ‘void* operator new(std::size_t)’
121 | return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
In file included from s2geometry-master/src/s2/util/gtl/btree_map.h:34,
from test.cpp:3:
s2geometry-master/src/s2/util/gtl/btree.h:597:58: warning: array subscript [32, 287] is outside array bounds of ‘absl::container_internal::Allocate<8, std::allocator<std::pair<int* const, std::pair<int, bool> > > >::M [32]’ [-Warray-bounds]
597 | btree_node *child(int i) const { return GetField<3>()[i]; }
| ^
In file included from /usr/local/include/c++/11.0.0/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
from /usr/local/include/c++/11.0.0/bits/allocator.h:46,
from /usr/local/include/c++/11.0.0/memory:64,
from s2geometry-master/src/s2/util/gtl/btree_map.h:30,
from test.cpp:3:
/usr/local/include/c++/11.0.0/ext/new_allocator.h:121:48: note: referencing an object of size between 48 and 256 allocated by ‘void* operator new(std::size_t)’
121 | return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~