Bug 109909 - vector<uchar>: Writing 8 bytes into 1 allocated byte
Summary: vector<uchar>: Writing 8 bytes into 1 allocated byte
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 13.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wstringop-overflow
  Show dependency treegraph
 
Reported: 2023-05-19 13:23 UTC by M Welinder
Modified: 2023-05-19 15:12 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Preprocessed source code (89.65 KB, application/gzip)
2023-05-19 13:23 UTC, M Welinder
Details

Note You need to log in before you can comment on or make changes to this bug.
Description M Welinder 2023-05-19 13:23:03 UTC
Created attachment 55119 [details]
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'