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

            Bug ID: 79095
           Summary: [7 regression] spurious stringop-overflow warning
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: s...@li-snyder.org
  Target Milestone: ---

hi -

gcc version 7.0.0 20170111 gives what appears to be a spurious warning
for this example when compiling with -O3 (tested on x86_64-pc-linux-gnu):

================================================================
#include <vector>

void foo(std::vector<unsigned int> &v);

void vtest()
{
  std::vector<unsigned int> v;
  foo (v);
  //if (v.size() > 0)
  {
    v.resize (v.size()-1);
  }
}
================================================================


$ gcc -c -O3  x.cc
In function ‘void vtest()’:
cc1plus: warning: ‘void* __builtin_memset(void*, int, long unsigned int)’:
specified size 18446744073709551612 exceeds maximum object size
9223372036854775807 [-Wstringop-overflow=]
cc1plus: warning: ‘void* __builtin_memset(void*, int, long unsigned int)’:
specified size 18446744073709551612 exceeds maximum object size
9223372036854775807 [-Wstringop-overflow=]
cc1plus: warning: ‘void* __builtin_memset(void*, int, long unsigned int)’:
specified size 18446744073709551612 exceeds maximum object size
9223372036854775807 [-Wstringop-overflow=]


The size reported is -4 as an unsigned, so the warning must be coming from
considering the possibility that v.size() is 0.  But we really shouldn't
be warning unless it can be shown that foo() can leave the vector empty,
and in any case adding the explicit test on the vector size (shown commented
out) does not get rid of the warning.

Reply via email to