Repository: baldurk/renderdoc

Issue #2187: Build warnings (Warray-bounds)
Created: 2021-02-20T22:10:35Z
Description
I'm maintaining an ebuild for RenderDoc on Gentoo (not in main tree, but will hopefully be sometime in the future) and when compiling I get "QA notices" from the compilation based on the Warray-bounds compilation flags.
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 30 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 25 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset [24, 25] is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 25 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset [24, 25] is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 25 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 30 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 25 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset [24, 25] is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 25 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset [24, 25] is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 25 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset [24, 25] is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 25 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 29 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset [24, 25] is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 25 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 30 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 25 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset [24, 25] is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset 25 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]
 * /usr/include/bits/string_fortified.h:29:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset [24, 25] is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Warray-bounds]

Steps to reproduce
Compile the v1.12 version on Gentoo using gcc-10.2.0.
Environment
Portage 3.0.14
python 3.8.8-final-0
gcc-10.2.0
glibc-2.32-r7
5.9.8-gentoo x86_64
System uname: Linux-5.9.8-gentoo-x86_64-AMD_Ryzen_9_3950X_16-Core_Processor-with-glibc2.2.5
sh bash 5.1_p4
ld GNU ld (Gentoo 2.35.2 p1) 2.35.2
app-shells/bash:          5.1_p4::gentoo
dev-lang/perl:            5.32.1::gentoo
dev-lang/python:          3.8.8::gentoo, 3.9.2::gentoo
dev-util/cmake:           3.19.5::gentoo
dev-util/pkgconfig:       0.29.2::gentoo
sys-apps/baselayout:      2.7-r1::gentoo
sys-apps/sandbox:         2.20::gentoo
sys-devel/autoconf:       2.13-r1::gentoo, 2.69-r5::gentoo
sys-devel/automake:       1.16.3-r1::gentoo
sys-devel/binutils:       2.35.2::gentoo
sys-devel/gcc:            10.2.0-r5::gentoo
sys-devel/gcc-config:     2.3.3::gentoo
sys-devel/libtool:        2.4.6-r6::gentoo
sys-devel/make:           4.3::gentoo
sys-kernel/linux-headers: 5.11::gentoo (virtual/os-headers)
sys-libs/glibc:           2.32-r7::gentoo
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=native -O3 -pipe -fomit-frame-pointer"
CHOST="x86_64-pc-linux-gnu"
CXXFLAGS="-march=native -O3 -pipe -fomit-frame-pointer"
EMERGE_DEFAULT_OPTS="--jobs=5 --with-bdeps=y --load-average=30 --keep-going"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j16 -l16"

RenderDoc version: 1.12
Operating System: Gentoo Linux
Graphics API: N/A

Duplicate issue #2283: offset 25 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Werror=array-bounds]
Created: 2021-05-28T04:29:51Z
Description
Just checking out the fresh version and building it.
Steps to reproduce

git checkout
mkdir build && cd build
cmake ..
make

Environment

RenderDoc version: 2ddf567
Operating System: Linux
Graphics API: N/A


gcc (Solus) 10.2.0

compiling renderdoc_python.cxx
In file included from ../../renderdoc/api/replay/renderdoc_replay.h:56,
                 from renderdoc_python.cxx:4374:
In member function ‘void rdcstr::insert(size_t, const char*, size_t)’,
    inlined from ‘void rdcstr::append(const char*, size_t)’ at ../../renderdoc/api/replay/rdcstr.h:325:61,
    inlined from ‘rdcstr& rdcstr::operator+=(const char*)’ at ../../renderdoc/api/replay/rdcstr.h:602:11,
    inlined from ‘static swig_type_info* TypeConversion<T, isEnum>::GetTypeInfo() [with T = D3D11Pipe::ConstantBuffer; bool isEnum = false]’ at ../../qrenderdoc/Code/pyrenderdoc/pyconversion.h:43:18,
    inlined from ‘static int TypeConversion<T, isEnum>::ConvertFromPy(PyObject*, T&) [with T = D3D11Pipe::ConstantBuffer; bool isEnum = false]’ at ../../qrenderdoc/Code/pyrenderdoc/pyconversion.h:51:44,
    inlined from ‘static int TypeConversion<rdcarray<U>, false>::ConvertFromPy(PyObject*, rdcarray<U>&, int*) [with U = D3D11Pipe::ConstantBuffer]’ at ../../qrenderdoc/Code/pyrenderdoc/pyconversion.h:579:49:
../../renderdoc/api/replay/rdcstr.h:379:11: error: ‘void* memcpy(void*, const void*, size_t)’ offset 25 is out of the bounds [0, 24] of object ‘baseTypeName’ with type ‘rdcstr’ [-Werror=array-bounds]
  379 |     memcpy(str + offset, instr, length);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from renderdoc_python.cxx:4378:
../../qrenderdoc/Code/pyrenderdoc/pyconversion.h: In static member function ‘static int TypeConversion<rdcarray<U>, false>::ConvertFromPy(PyObject*, rdcarray<U>&, int*) [with U = D3D11Pipe::ConstantBuffer]’:
../../qrenderdoc/Code/pyrenderdoc/pyconversion.h:42:12: note: ‘baseTypeName’ declared here
   42 |     rdcstr baseTypeName = TypeName<T>();

Closing comment (2021-05-28T09:05:29Z): This is a duplicate of #2187, the warning is a false positive caused by a compiler bug. In that issue there were other messages that were more clearly compiler bugs with impossible offsets listed as being accessed.
As with that bug I can't reproduce the problem with the steps you've given on ubuntu's gcc 10.3.0 - perhaps the bug has been fixed since 10.2.0, although in #2187 the problem may have been caused by passing extra options to the compiler. It might be useful for you to double check that you're not passing any extra settings yourself somehow implicitly, or that your distro hasn't baked in some compile options by default (if that's possible).