public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109909] New: vector<uchar>: Writing 8 bytes into 1 allocated byte
@ 2023-05-19 13:23 terra at gnome dot org
  0 siblings, 0 replies; only message in thread
From: terra at gnome dot org @ 2023-05-19 13:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109909
           Summary: vector<uchar>: Writing 8 bytes into 1 allocated byte
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: terra at gnome dot org
  Target Milestone: ---

Created attachment 55119
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55119&action=edit
Preprocessed source code

The following piece of code, when compiled, shows a warning about writing 8
bytes into an address for which 1 byte was allocated.

Tentatively blaming the compiler although it might just as well be a library
issue.

Severity could be anything from fairly trivial ("just a bogus warning") to
really bad ("overwriting memory it should not").

Both "-std=gnu++20" and "-O3" seem to be required to trigger the warning.


$ cat ttt.C
#include <vector>


struct Oink {
  using utype = unsigned char;// in gcc13 this triggers
  //
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/stl_construct.h:97:14:
warning: writing 8 bytes into a region of size 1 [-Wstringop-overflow=]
  // using the next line does not.
  // using utype = long long;
  utype mValue = 0;
};

std::vector<Oink> mSty;

void foo() {
  mSty.resize(1);
}




$ /usr/local/products/gcc/13.1.0/bin/g++  -std=gnu++20 -c -v -O3 ttt.C
Using built-in specs.
COLLECT_GCC=/usr/local/products/gcc/13.1.0/bin/g++
Target: x86_64-suse-linux
Configured with: ../../gcc-13.1.0/configure --enable-languages=c,c++,fortran
--enable-targets=x86_64-suse-linux,i686-suse-linux
--prefix=/usr/local/products/gcc/13.1.0 --with-gnu-as
--with-as=/usr/local/products/gcc/binutils-2.40/bin/as
--with-ld=/usr/local/products/gcc/binutils-2.40/bin/ld.gold --enable-link-mutex
--enable-gnu-indirect-functions --enable-linux-futex --enable-threads=posix
--enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new
x86_64-suse-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.1.0 (GCC) 
COLLECT_GCC_OPTIONS='-std=gnu++20' '-c' '-v' '-O3' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/local/products/gcc/13.1.0/lib/gcc/x86_64-suse-linux/13.1.0/cc1plus -quiet
-v -D_GNU_SOURCE ttt.C -quiet -dumpbase ttt.C -dumpbase-ext .C -mtune=generic
-march=x86-64 -O3 -std=gnu++20 -version -o /tmp/ccxuQqee.s
GNU C++20 (GCC) version 13.1.0 (x86_64-suse-linux)
        compiled by GNU C version 13.1.0, GMP version 6.2.1, MPFR version
4.2.0, MPC version 1.3.1, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/usr/local/products/gcc/13.1.0/lib64/gcc/x86_64-suse-linux/13.1.0/../../../../x86_64-suse-linux/include"
#include "..." search starts here:
#include <...> search starts here:

/usr/local/products/gcc/13.1.0/lib64/gcc/x86_64-suse-linux/13.1.0/../../../../include/c++/13.1.0

/usr/local/products/gcc/13.1.0/lib64/gcc/x86_64-suse-linux/13.1.0/../../../../include/c++/13.1.0/x86_64-suse-linux

/usr/local/products/gcc/13.1.0/lib64/gcc/x86_64-suse-linux/13.1.0/../../../../include/c++/13.1.0/backward
 /usr/local/products/gcc/13.1.0/lib64/gcc/x86_64-suse-linux/13.1.0/include
 /usr/local/include
 /usr/local/products/gcc/13.1.0/include

/usr/local/products/gcc/13.1.0/lib64/gcc/x86_64-suse-linux/13.1.0/include-fixed
 /usr/include
End of search list.
Compiler executable checksum: 759d8432ee23c1bd4b520a57099ed580
In file included from
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/stl_iterator.h:85,
                 from
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/stl_algobase.h:67,
                 from
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/vector:62,
                 from ttt.C:1:
In function ‘constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*,
_Args&& ...) [with _Tp = Oink; _Args = {Oink}]’,
    inlined from ‘static constexpr void
std::allocator_traits<std::allocator<_Up> >::construct(allocator_type&, _Up*,
_Args&& ...) [with _Up = Oink; _Args = {Oink}; _Tp = Oink]’ at
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/alloc_traits.h:539:21,
    inlined from ‘constexpr void std::__relocate_object_a(_Tp*, _Up*,
_Allocator&) [with _Tp = Oink; _Up = Oink; _Allocator = allocator<Oink>]’ at
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/stl_uninitialized.h:1072:26,
    inlined from ‘constexpr _ForwardIterator
std::__relocate_a_1(_InputIterator, _InputIterator, _ForwardIterator,
_Allocator&) [with _InputIterator = Oink*; _ForwardIterator = Oink*; _Allocator
= allocator<Oink>]’ at
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/stl_uninitialized.h:1100:26,
    inlined from ‘constexpr _ForwardIterator std::__relocate_a(_InputIterator,
_InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = Oink*;
_ForwardIterator = Oink*; _Allocator = allocator<Oink>]’ at
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/stl_uninitialized.h:1142:33,
    inlined from ‘static constexpr std::vector<_Tp, _Alloc>::pointer
std::vector<_Tp, _Alloc>::_S_relocate(pointer, pointer, pointer,
_Tp_alloc_type&) [with _Tp = Oink; _Alloc = std::allocator<Oink>]’ at
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/stl_vector.h:504:26,
    inlined from ‘constexpr void std::vector<_Tp,
_Alloc>::_M_default_append(size_type) [with _Tp = Oink; _Alloc =
std::allocator<Oink>]’ at
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/vector.tcc:676:16,
    inlined from ‘constexpr void std::vector<_Tp, _Alloc>::resize(size_type)
[with _Tp = Oink; _Alloc = std::allocator<Oink>]’ at
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/stl_vector.h:1011:21,
    inlined from ‘void foo()’ at ttt.C:15:14:
/usr/local/products/gcc/13.1.0/include/c++/13.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)...); }
      |             
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/x86_64-suse-linux/bits/c++allocator.h:33,
                 from
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/allocator.h:46,
                 from
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/vector:63:
In member function ‘_Tp* std::__new_allocator<_Tp>::allocate(size_type, const
void*) [with _Tp = Oink]’,
    inlined from ‘constexpr _Tp* std::allocator< <template-parameter-1-1>
>::allocate(std::size_t) [with _Tp = Oink]’ at
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/allocator.h:198:40,
    inlined from ‘static constexpr _Tp*
std::allocator_traits<std::allocator<_Up> >::allocate(allocator_type&,
size_type) [with _Tp = Oink]’ at
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/alloc_traits.h:482:28,
    inlined from ‘constexpr std::_Vector_base<_Tp, _Alloc>::pointer
std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = Oink;
_Alloc = std::allocator<Oink>]’ at
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/stl_vector.h:378:33,
    inlined from ‘constexpr void std::vector<_Tp,
_Alloc>::_M_default_append(size_type) [with _Tp = Oink; _Alloc =
std::allocator<Oink>]’ at
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/vector.tcc:663:45,
    inlined from ‘constexpr void std::vector<_Tp, _Alloc>::resize(size_type)
[with _Tp = Oink; _Alloc = std::allocator<Oink>]’ at
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/stl_vector.h:1011:21,
    inlined from ‘void foo()’ at ttt.C:15:14:
/usr/local/products/gcc/13.1.0/include/c++/13.1.0/bits/new_allocator.h:147:55:
note: destination object of size 1 allocated by ‘operator new’
  147 |         return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp)));
      |                                                       ^
COLLECT_GCC_OPTIONS='-std=gnu++20' '-c' '-v' '-O3' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/local/products/gcc/binutils-2.40/bin/as -v --64 -o ttt.o /tmp/ccxuQqee.s
GNU assembler version 2.40 (x86_64-suse-linux) using BFD version (GNU Binutils)
2.40
COMPILER_PATH=/usr/local/products/gcc/13.1.0/lib/gcc/x86_64-suse-linux/13.1.0/:/usr/local/products/gcc/13.1.0/lib/gcc/x86_64-suse-linux/13.1.0/:/usr/local/products/gcc/13.1.0/lib/gcc/x86_64-suse-linux/:/usr/local/products/gcc/13.1.0/lib64/gcc/x86_64-suse-linux/13.1.0/:/usr/local/products/gcc/13.1.0/lib64/gcc/x86_64-suse-linux/
LIBRARY_PATH=/usr/local/products/gcc/13.1.0/lib64/gcc/x86_64-suse-linux/13.1.0/:/usr/local/products/gcc/13.1.0/lib64/gcc/x86_64-suse-linux/13.1.0/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/local/products/gcc/13.1.0/lib64/gcc/x86_64-suse-linux/13.1.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-std=gnu++20' '-c' '-v' '-O3' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-19 13:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-19 13:23 [Bug c++/109909] New: vector<uchar>: Writing 8 bytes into 1 allocated byte terra at gnome dot org

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).