https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112370
Bug ID: 112370 Summary: -Wfree-nonheap-object in std::vector dtor on sapphirerapids with -O3 Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: alexander.gr...@tu-dresden.de Target Milestone: --- I have some code (from PTorch) which shows a bogus -Wfree-nonheap-object warning when compiled with `-O3 -march=sapphirerapids`: In file included from /software/GCCcore/12.2.0/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/c++allocator.h:33, from /software/GCCcore/12.2.0/include/c++/12.2.0/bits/allocator.h:46, from /software/GCCcore/12.2.0/include/c++/12.2.0/memory:64, from /src/third_party/ideep/mkl-dnn/src/utils/compatible.hpp:23, from /src/third_party/ideep/mkl-dnn/src/backend/dnnl/dnnl_backend.cpp:19: In member function 'void std::__new_allocator<_Tp>::deallocate(_Tp*, size_type) [with _Tp = long int]', inlined from 'static void std::allocator_traits<std::allocator<_Tp1> >::deallocate(allocator_type&, pointer, size_type) [with _Tp = long int]' at /software/GCCcore/12.2.0/include/c++/12.2.0/bits/alloc_traits.h:496:23, inlined from 'void std::_Vector_base<_Tp, _Alloc>::_M_deallocate(pointer, std::size_t) [with _Tp = long int; _Alloc = std::allocator<long int>]' at /software/GCCcore/12.2.0/include/c++/12.2.0/bits/stl_vector.h:387:19, inlined from 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = long int; _Alloc = std::allocator<long int>]' at /software/GCCcore/12.2.0/include/c++/12.2.0/bits/stl_vector.h:366:15, inlined from 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = long int; _Alloc = std::allocator<long int>]' at /software/GCCcore/12.2.0/include/c++/12.2.0/bits/stl_vector.h:733:7, inlined from 'virtual void dnnl::graph::impl::dnnl_impl::bn_folding_t::execute(const dnnl::stream&, const std::unordered_map<int, dnnl::memory>&) const' at /src/third_party/ideep/mkl-dnn/src/backend/dnnl/op_executable.hpp:1060:63: /software/GCCcore/12.2.0/include/c++/12.2.0/bits/new_allocator.h:158:26: error: 'void operator delete(void*, std::size_t)' called on pointer '<unknown>' with nonzero offset [1, 9223372036854775800] [-Werror=free-nonheap-object] 158 | _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n)); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ In member function '_Tp* std::__new_allocator<_Tp>::allocate(size_type, const void*) [with _Tp = long int]', inlined from 'static _Tp* std::allocator_traits<std::allocator<_Tp1> >::allocate(allocator_type&, size_type) [with _Tp = long int]' at /software/GCCcore/12.2.0/include/c++/12.2.0/bits/alloc_traits.h:464:28, inlined from 'std::_Vector_base<_Tp, _Alloc>::pointer std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = long int; _Alloc = std::allocator<long int>]' at /software/GCCcore/12.2.0/include/c++/12.2.0/bits/stl_vector.h:378:33, inlined from 'void std::vector<_Tp, _Alloc>::_M_range_initialize(_ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator = const long int*; _Tp = long int; _Alloc = std::allocator<long int>]' at /software/GCCcore/12.2.0/include/c++/12.2.0/bits/stl_vector.h:1687:25, inlined from 'std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = const long int*; <template-parameter-2-2> = void; _Tp = long int; _Alloc = std::allocator<long int>]' at /software/GCCcore/12.2.0/include/c++/12.2.0/bits/stl_vector.h:706:23, inlined from 'dnnl::memory::dims dnnl::memory::desc::dims() const' at /src/third_party/ideep/mkl-dnn/third_party/oneDNN/include/oneapi/dnnl/dnnl.hpp:2677:66, inlined from 'virtual void dnnl::graph::impl::dnnl_impl::bn_folding_t::execute(const dnnl::stream&, const std::unordered_map<int, dnnl::memory>&) const' at /src/third_party/ideep/mkl-dnn/src/backend/dnnl/op_executable.hpp:1060:63: /software/GCCcore/12.2.0/include/c++/12.2.0/bits/new_allocator.h:137:48: note: returned from 'void* operator new(std::size_t)' 137 | return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp))); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ Command used: g++ -O3 -march=sapphirerapids -Wall -Werror -std=gnu++17 -c -o a.o pre.cpp Preprocessed source is attached (rather large, sorry) The bug does not show when using another optimization level or arch. E.g. `-march=cooperlake` works.