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

            Bug ID: 92879
           Summary: incorrect warning of __builtin_memset offset is out of
                    the bounds on zero-size allocation and initialization
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cas43 at cs dot stanford.edu
  Target Milestone: ---

DIAGNOSTIC:

g++ prog.cpp -c -Wall -O3
In constructor ‘S::S(int)’,
    inlined from ‘(static initializers for prog.cpp)’ at prog.cpp:16:6:
prog.cpp:13:30: warning: ‘void* __builtin_memset(void*, int, long unsigned
int)’ offset [0, 3] is out of the bounds [0, 0]
[]8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Warray-bounds-Warray-bounds]8;;]
   13 |         for(int i=0;i<m;i++) new(p+i)int();
      |                              ^~~~~~~~~~~~~


CODE:

inline void* operator new(long unsigned int, void* v) noexcept
{
    return v;
}
struct S
{
    int* p;
    int m;
    S(int i)
    {
        m=i;
        p=(int*)new unsigned char[sizeof(int)*m];
        for(int i=0;i<m;i++) new(p+i)int();
    }
};
S a(0);


COMPILER:

Using built-in specs.
COLLECT_GCC=/home/craig/new-gcc/i-trunk/bin/g++
COLLECT_LTO_WRAPPER=/home/craig/new-gcc/i-trunk/libexec/gcc/x86_64-pc-linux-gnu/10.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../s-trunk/configure --prefix=/home/craig/new-gcc/i-trunk
--disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.0 20191209 (experimental) (GCC) 


EXPLANATION:

The body of the initialization loop never executes, so no out-of-bounds is
possible.

Reply via email to