[Bug libstdc++/86516] Spurious warning __builtin_memset at O3 when protected by a conditional involving empty()

2018-07-23 Thread paulg at chiark dot greenend.org.uk
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86516

--- Comment #2 from Paul Gotch  ---
I can reproduce this at will with GCC 7.3 it does not reproduce with GCC 8

// Compile with g++ -c -Wextra -Wall -Werror -O3 test.cpp

#include 

class Foo
{
public:

Foo() {}

virtual ~Foo()
{
}

// warning only reproduces if this calls inner and is virtual
virtual void outer()
{
inner();
}

void inner()
{
while ( ! vInt.empty() )
{
vInt.resize( vInt.size() - 1 );
}
}

std::vector vInt;
};

// An instantiation of Foo is required for warning to reproduce
void* makeFoo()
{
return new Foo();
}

[Bug libstdc++/86516] New: Spurious warning __builtin_memset at O3 when protected by a conditional involving empty()

2018-07-13 Thread paulg at chiark dot greenend.org.uk
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86516

Bug ID: 86516
   Summary: Spurious warning __builtin_memset at O3  when
protected by a conditional involving empty()
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: paulg at chiark dot greenend.org.uk
  Target Milestone: ---

This is spurious diagnostic regression in GCC 7 and beyond and is related to
two previous bugs.

The first one was was 82698 which was resolved as a duplicate of 88641. However
the workaround applied for 88641 is not complete and does not solve the
problem.

The issue is that at O3 if you do

std::vector v;

if(c.size() > 0)
 c.resize(c.size() - 1);

then you no longer get a spurious builtin memset warning in 7.3 however if
instead you do

if(! c.empty())
 c.resize(c.size() -1);

it produces an erroneous warning. The fundamental problem is a dataflow
analysis issue which is somewhat difficult to fix.

In 88641 decorations were added to libstdc++ to avoid the warning however they
seem to have only been added to size() not empty() so the 2nd form of code
above still produces a spurious warning.

[Bug tree-optimization/80641] missed optimization with with std::vector resize in loop

2018-01-31 Thread paulg at chiark dot greenend.org.uk
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80641

--- Comment #10 from Paul Gotch  ---
I'm afraid the changes made to libstdc++ have only solved part of the
regression if you say something like

std::vector v;

if(c.size() > 0)
 c.resize(c.size() - 1);

then you no longer get a warning in 7.3 however if instead you do

if(! c.empty())
 c.resize(c.size() -1);

the warning is produced just as in early 7.x releases. No warning is produced
in 6.x so this is still a regression.

I presume this happens as empty wasn't annotated in libstdc++ and the
underlying data flow analysis bug is yet to be fixed.

[Bug ipa/82698] New: Spurious warning __builtin_memset at O3

2017-10-24 Thread paulg at chiark dot greenend.org.uk
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82698

Bug ID: 82698
   Summary: Spurious warning __builtin_memset at O3
   Product: gcc
   Version: 7.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: ipa
  Assignee: unassigned at gcc dot gnu.org
  Reporter: paulg at chiark dot greenend.org.uk
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

With the following code fragment

#include 

void foo(std::vector & bar)
{
bar.resize(bar.size() - 1);
}

compiled with

g++ -c -O3 -Wall -Wextra test.cpp

the following is produced

cc1plus: warning: ‘void* __builtin_memset(void*, int, long unsigned int)’:
specified size 18446744073709551612 exceeds maximum object size
9223372036854775807 -Wstringop-overflow=]

Since the compiler cannot know if the user has arranged to never pass a
argument which would produce this problem this seems like overreach on the part
of the compiler.