[Bug c++/81408] Lots of new -Wunsafe-loop-optimizations warnings with 7 compared to 6

2017-07-13 Thread amker at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81408

--- Comment #8 from amker at gcc dot gnu.org ---
After I deleted -funsafe-loop-optimizations in GIMPLE passes, there is no
"unsafe-loop-optimizations" for any GIMPLE optimizers.  This message in
actuality means missed loop optimizations.  I am preparing patch dumping the
message to category MSG_MISSED_OPTIMIZATION.

On the other hand, I noticed the niter analysis for c++ iterator loop is bad. 
I will create another PR for it.

[Bug c++/81408] Lots of new -Wunsafe-loop-optimizations warnings with 7 compared to 6

2017-07-12 Thread amker at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81408

amker at gcc dot gnu.org changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |amker at gcc dot gnu.org

--- Comment #7 from amker at gcc dot gnu.org ---
(In reply to Martin Liška from comment #6)
> And there's sample which started to be reported with Bin's revision r238641:
> 
> namespace a {
> void b () __attribute__ ((__noreturn__));
> template  struct d;
> template  struct d
> {
>   typedef e f;
> };
> struct g
> {
>   template  using i = h *;
> };
> }
> using a::d;
> template  class k
> {
>   j l;
> 
> public:
>   typename d::f operator* () {}
>   void operator++ () { ++l; }
>   j
>   aa ()
>   {
> return l;
>   }
> };
> template 
> bool
> operator!= (k o, k p2)
> {
>   return o.aa () != p2.aa ();
> }
> struct p;
> namespace a {
> struct F
> {
>   struct q
>   {
> using ai = g::i;
>   };
>   using r = q::ai;
> };
> class H
> {
> public:
>   k begin ();
>   k end ();
> };
> int s;
> class I
> {
> public:
>   void
>   aq (char)
>   {
> if (s)
>   b ();
>   }
> };
> class u : public I
> {
> public:
>   void
>   operator<< (u o (u))
>   {
> o (*this);
>   }
>   u operator<< (void *);
> };
> template 
> at
> av (au o)
> {
>   o.aq ('\n');
> }
> u ax;
> }
> struct p
> {
>   char *ay;
> };
> a::H t;
> void
> ShowHelpListCommands ()
> {
>   for (auto c : t)
> a::ax << c.ay << a::av;
> }

Yes, it's very likely my fault.  Thanks for reducing the test case.  I will
investigate it.

[Bug c++/81408] Lots of new -Wunsafe-loop-optimizations warnings with 7 compared to 6

2017-07-12 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81408

--- Comment #6 from Martin Liška  ---
And there's sample which started to be reported with Bin's revision r238641:

namespace a {
void b () __attribute__ ((__noreturn__));
template  struct d;
template  struct d
{
  typedef e f;
};
struct g
{
  template  using i = h *;
};
}
using a::d;
template  class k
{
  j l;

public:
  typename d::f operator* () {}
  void operator++ () { ++l; }
  j
  aa ()
  {
return l;
  }
};
template 
bool
operator!= (k o, k p2)
{
  return o.aa () != p2.aa ();
}
struct p;
namespace a {
struct F
{
  struct q
  {
using ai = g::i;
  };
  using r = q::ai;
};
class H
{
public:
  k begin ();
  k end ();
};
int s;
class I
{
public:
  void
  aq (char)
  {
if (s)
  b ();
  }
};
class u : public I
{
public:
  void
  operator<< (u o (u))
  {
o (*this);
  }
  u operator<< (void *);
};
template 
at
av (au o)
{
  o.aq ('\n');
}
u ax;
}
struct p
{
  char *ay;
};
a::H t;
void
ShowHelpListCommands ()
{
  for (auto c : t)
a::ax << c.ay << a::av;
}

[Bug c++/81408] Lots of new -Wunsafe-loop-optimizations warnings with 7 compared to 6

2017-07-12 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81408

Martin Liška  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-07-12
 CC||amker at gcc dot gnu.org,
   ||glisse at gcc dot gnu.org,
   ||marxin at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #5 from Martin Liška  ---
Confirmed, I reduced one test-case:

$ cat pr81408.ii
template  class d
{
  b e;

public:
  int operator* () {}
  void operator++ () { ++e; }
  b
  base ()
  {
return e;
  }
};
template 
bool
operator!= (d i, d j)
{
  return i.base () - j.base ();
}
template  class k;
template  struct m;
template  struct m
{
  using l = a *;
};
struct p : m
{
  d begin ();
  d end ();
} n;
void
o ()
{
  for (auto c : n)
;
}

Which started to be recognized with r242638. And I also noticed the original
unreduced test-case started to be diagnosed with r238641.
That said it's probably better optimizer work that shows more warnings, am I
right?

[Bug c++/81408] Lots of new -Wunsafe-loop-optimizations warnings with 7 compared to 6

2017-07-12 Thread j...@jak-linux.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81408

--- Comment #4 from Julian Andres Klode  ---
Note that apt has 1219 loops, so 134 is almost 11% of the loops causing the
warning, compared to about 0.7% (8) before.

[Bug c++/81408] Lots of new -Wunsafe-loop-optimizations warnings with 7 compared to 6

2017-07-12 Thread j...@jak-linux.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81408

--- Comment #3 from Julian Andres Klode  ---
7.1.0-9 corresponds to "SVN 20170705 (r250006) from the gcc-7-branch."

[Bug c++/81408] Lots of new -Wunsafe-loop-optimizations warnings with 7 compared to 6

2017-07-12 Thread j...@jak-linux.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81408

--- Comment #2 from Julian Andres Klode  ---
Build log with -v:

Using built-in specs.
COLLECT_GCC=/usr/bin/g++-7
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 7.1.0-9'
--with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-7
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie
--with-system-zlib --with-target-system-zlib --enable-objc-gc=auto
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 7.1.0 (Debian 7.1.0-9) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-O2' '-Wunsafe-loop-optimizations'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/7/cc1plus -E -quiet -v -imultiarch
x86_64-linux-gnu -D_GNU_SOURCE a.cc -mtune=generic -march=x86-64
-Wunsafe-loop-optimizations -O2 -fpch-preprocess -o a.ii
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/7"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/7
 /usr/include/x86_64-linux-gnu/c++/7
 /usr/include/c++/7/backward
 /usr/lib/gcc/x86_64-linux-gnu/7/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-O2' '-Wunsafe-loop-optimizations'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/7/cc1plus -fpreprocessed a.ii -quiet -dumpbase
a.cc -mtune=generic -march=x86-64 -auxbase a -O2 -Wunsafe-loop-optimizations
-version -o a.s
GNU C++14 (Debian 7.1.0-9) version 7.1.0 (x86_64-linux-gnu)
compiled by GNU C version 7.1.0, GMP version 6.1.2, MPFR version 3.1.5,
MPC version 1.0.3, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++14 (Debian 7.1.0-9) version 7.1.0 (x86_64-linux-gnu)
compiled by GNU C version 7.1.0, GMP version 6.1.2, MPFR version 3.1.5,
MPC version 1.0.3, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 3681302eda59faba4e53a905eca4bf72
a.cc: In function ‘void ShowHelpListCommands(const
std::vector&)’:
a.cc:11:24: warning: missed loop optimization, the loop counter may overflow
[-Wunsafe-loop-optimizations]
for (auto const : Cmds)
^~~~
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-O2' '-Wunsafe-loop-optimizations'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as -v --64 -o a.o a.s
GNU assembler version 2.28 (x86_64-linux-gnu) using BFD version (GNU Binutils
for Debian) 2.28
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-O2' '-Wunsafe-loop-optimizations'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'

[Bug c++/81408] Lots of new -Wunsafe-loop-optimizations warnings with 7 compared to 6

2017-07-12 Thread j...@jak-linux.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81408

--- Comment #1 from Julian Andres Klode  ---
Created attachment 41727
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41727=edit
preprocessed source of a.cc