Skip to content

Instantly share code, notes, and snippets.

@paleolimbot
Last active October 26, 2020 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paleolimbot/51db5e587b5f3e57a637b6a24655fe87 to your computer and use it in GitHub Desktop.
Save paleolimbot/51db5e587b5f3e57a637b6a24655fe87 to your computer and use it in GitHub Desktop.
FROM rocker/r-devel:latest
RUN apt update && apt install -y git flex
RUN git clone git://gcc.gnu.org/git/gcc.git gcc11
RUN cd gcc11 && ./contrib/download_prerequisites
RUN mkdir gcc-build && cd gcc-build && ../gcc11/configure -disable-multilib --enable-languages=c,c++,fortran
RUN cd gcc-build && make -j4 && make install
RUN echo 'LD_LIBRARY_PATH="/usr/local/lib64:${R_LD_LIBRARY_PATH}:${LD_LIBRARY_PATH}"' >> /usr/lib/R/etc/ldpaths
RUN mkdir ~/.R && echo 'CXX11=/usr/local/bin/g++' > ~/.R/Makevars && echo 'CXX=/usr/local/bin/g++' >> ~/.R/Makevars && echo 'CC=/usr/local/bin/gcc' >> ~/.R/Makevars
RUN echo 'CCFLAGS = -Wall -pedantic -O2' >> ~/.R/Makevars && echo 'CXXFLAGS = -Wall -pedantic -O2' >> ~/.R/Makevars && echo 'CXX11FLAGS = -Wall -pedantic -O2' >> ~/.R/Makevars
CMD /bin/bash
#include "s2/util/gtl/btree_map.h"
int main() {
gtl::btree_map<int, int> map;
map[4] = 4;
return 0;
}
# build docker image with gcc11 (takes several hours)
docker build . --tag r-gcc11
docker run --rm r-gcc11 g++ --version
# with r-spatial/s2
curl -L https://github.com/r-spatial/s2/archive/master.zip --output s2-r.zip
unzip s2-r.zip
docker run --rm -v $(pwd):/test -w /test r-gcc11 g++ -std=gnu++11 -I s2-master/inst/include -O2 -DNDEBUG -Warray-bounds test.cpp -o test
# 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 test
@paleolimbot
Copy link
Author

paleolimbot commented Oct 25, 2020

Note that all of

  • gcc11/devel
  • map[4] = 4; (i.e., insertion)
  • -DNDEBUG and
  • -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++ --version
g++ (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 test
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: 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)));
      |                                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment