public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "aclopte at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/106093] New: [Regression] False positive -Wstringop-overflow with -O3 when resizing std::vector
Date: Sun, 26 Jun 2022 21:31:23 +0000	[thread overview]
Message-ID: <bug-106093-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 106093
           Summary: [Regression] False positive -Wstringop-overflow with
                    -O3 when resizing std::vector
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aclopte at gmail dot com
  Target Milestone: ---

Created attachment 53202
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53202&action=edit
preprocessed reproducer

Very similar to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83239 and others.
This one reproduces on 12.1.0 but not on 11.2.0.

cat > repro.cpp << EOF
#include <vector>

template <typename T> struct Allocator {
  using value_type = T;

  Allocator() = default;

  T *allocate(unsigned long n) {
    return reinterpret_cast<T *>(::operator new(sizeof(T) * n));
  }

  void deallocate(T *ptr, unsigned long n) { ::operator delete(ptr); }
};

static std::vector<char, Allocator<char>> m_stream{};
void read_available() {
    m_stream.resize(1);
}
EOF

attached the preprocessed output

$ g++ -std=c++2a repro.cpp -S -O3

In function ‘constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*,
_Args&& ...) [with _Tp = char; _Args = {char}]’,
    inlined from ‘static constexpr
std::_Require<std::__and_<std::__not_<typename std::allocator_traits<
<template-parameter-1-1> >::__construct_helper<_Tp, _Args>::type>,
std::is_constructible<_Tp, _Args ...> > > std::allocator_traits<
<template-parameter-1-1> >::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp
= char; _Args = {char}; _Alloc = Allocator<char>]’ at
/usr/include/c++/12.1.0/bits/alloc_traits.h:263:21,
    inlined from ‘static constexpr decltype (std::allocator_traits<
<template-parameter-1-1> >::_S_construct(__a, __p,
(forward<_Args>)(std::allocator_traits< <template-parameter-1-1>
>::construct::__args)...)) std::allocator_traits< <template-parameter-1-1>
>::construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = char; _Args = {char};
_Alloc = Allocator<char>]’ at
/usr/include/c++/12.1.0/bits/alloc_traits.h:364:16,
    inlined from ‘constexpr void std::__relocate_object_a(_Tp*, _Up*,
_Allocator&) [with _Tp = char; _Up = char; _Allocator = Allocator<char>]’ at
/usr/include/c++/12.1.0/bits/stl_uninitialized.h:1064:26,
    inlined from ‘constexpr _ForwardIterator
std::__relocate_a_1(_InputIterator, _InputIterator, _ForwardIterator,
_Allocator&) [with _InputIterator = char*; _ForwardIterator = char*; _Allocator
= Allocator<char>]’ at
/usr/include/c++/12.1.0/bits/stl_uninitialized.h:1092:26,
    inlined from ‘constexpr _ForwardIterator std::__relocate_a(_InputIterator,
_InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = char*;
_ForwardIterator = char*; _Allocator = Allocator<char>]’ at
/usr/include/c++/12.1.0/bits/stl_uninitialized.h:1133:33,
    inlined from ‘static constexpr std::vector<_Tp, _Alloc>::pointer
std::vector<_Tp, _Alloc>::_S_relocate(pointer, pointer, pointer,
_Tp_alloc_type&) [with _Tp = char; _Alloc = Allocator<char>]’ at
/usr/include/c++/12.1.0/bits/stl_vector.h:504:26,
    inlined from ‘constexpr void std::vector<_Tp,
_Alloc>::_M_default_append(size_type) [with _Tp = char; _Alloc =
Allocator<char>]’ at /usr/include/c++/12.1.0/bits/vector.tcc:663:16,
    inlined from ‘constexpr void std::vector<_Tp, _Alloc>::resize(size_type)
[with _Tp = char; _Alloc = Allocator<char>]’ at
/usr/include/c++/12.1.0/bits/stl_vector.h:1011:21,
    inlined from ‘void read_available()’ at t/repro/repro.cc:17:20:
/usr/include/c++/12.1.0/bits/stl_construct.h:97:14: warning: writing 8 bytes
into a region of size 1 [-Wstringop-overflow=]
   97 |     { return ::new((void*)__location)
_Tp(std::forward<_Args>(__args)...); }
      |             
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

             reply	other threads:[~2022-06-26 21:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-26 21:31 aclopte at gmail dot com [this message]
2023-01-16 10:53 ` [Bug tree-optimization/106093] [12/13 Regression] " rguenth at gcc dot gnu.org
2023-01-16 13:14 ` redi at gcc dot gnu.org
2023-01-16 13:17 ` redi at gcc dot gnu.org
2023-05-08 12:24 ` [Bug tree-optimization/106093] [12/13/14 " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-106093-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).