public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112370] New: -Wfree-nonheap-object in std::vector dtor on sapphirerapids with -O3
@ 2023-11-03 15:13 alexander.grund@tu-dresden.de
  2023-11-03 15:32 ` [Bug c++/112370] " alexander.grund@tu-dresden.de
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: alexander.grund@tu-dresden.de @ 2023-11-03 15:13 UTC (permalink / raw)
  To: gcc-bugs

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.grund@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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/112370] -Wfree-nonheap-object in std::vector dtor on sapphirerapids with -O3
  2023-11-03 15:13 [Bug c++/112370] New: -Wfree-nonheap-object in std::vector dtor on sapphirerapids with -O3 alexander.grund@tu-dresden.de
@ 2023-11-03 15:32 ` alexander.grund@tu-dresden.de
  2023-11-06  8:14 ` [Bug tree-optimization/112370] " alexander.grund@tu-dresden.de
  2023-11-06  8:15 ` alexander.grund@tu-dresden.de
  2 siblings, 0 replies; 4+ messages in thread
From: alexander.grund@tu-dresden.de @ 2023-11-03 15:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112370

--- Comment #1 from Alexander Grund <alexander.grund@tu-dresden.de> ---
Created attachment 56503
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56503&action=edit
Preprocessed source

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/112370] -Wfree-nonheap-object in std::vector dtor on sapphirerapids with -O3
  2023-11-03 15:13 [Bug c++/112370] New: -Wfree-nonheap-object in std::vector dtor on sapphirerapids with -O3 alexander.grund@tu-dresden.de
  2023-11-03 15:32 ` [Bug c++/112370] " alexander.grund@tu-dresden.de
@ 2023-11-06  8:14 ` alexander.grund@tu-dresden.de
  2023-11-06  8:15 ` alexander.grund@tu-dresden.de
  2 siblings, 0 replies; 4+ messages in thread
From: alexander.grund@tu-dresden.de @ 2023-11-06  8:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112370

--- Comment #2 from Alexander Grund <alexander.grund@tu-dresden.de> ---
FWIW: I tried to run cvise on this however it created an invalid example where
indeed a non-heap pointer would be freed. I'll attach it anyway for reference
as it took hours to run the reduce

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/112370] -Wfree-nonheap-object in std::vector dtor on sapphirerapids with -O3
  2023-11-03 15:13 [Bug c++/112370] New: -Wfree-nonheap-object in std::vector dtor on sapphirerapids with -O3 alexander.grund@tu-dresden.de
  2023-11-03 15:32 ` [Bug c++/112370] " alexander.grund@tu-dresden.de
  2023-11-06  8:14 ` [Bug tree-optimization/112370] " alexander.grund@tu-dresden.de
@ 2023-11-06  8:15 ` alexander.grund@tu-dresden.de
  2 siblings, 0 replies; 4+ messages in thread
From: alexander.grund@tu-dresden.de @ 2023-11-06  8:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112370

--- Comment #3 from Alexander Grund <alexander.grund@tu-dresden.de> ---
Created attachment 56513
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56513&action=edit
INVALID reduced example (after running cvise on the former example)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-06  8:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-03 15:13 [Bug c++/112370] New: -Wfree-nonheap-object in std::vector dtor on sapphirerapids with -O3 alexander.grund@tu-dresden.de
2023-11-03 15:32 ` [Bug c++/112370] " alexander.grund@tu-dresden.de
2023-11-06  8:14 ` [Bug tree-optimization/112370] " alexander.grund@tu-dresden.de
2023-11-06  8:15 ` alexander.grund@tu-dresden.de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).