diff options
author | Martin Sebor <msebor@redhat.com> | 2017-12-16 22:37:22 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2017-12-16 15:37:22 -0700 |
commit | d43568222a4564e22a6ffd370481e11ba031b318 (patch) | |
tree | 49759439d19f1c2f45fbb5f75e0ad9ff5e3712a4 /gcc | |
parent | 1eaa31d84014c78a16409ef3c08e164dee78b56f (diff) | |
download | gcc-d43568222a4564e22a6ffd370481e11ba031b318.zip gcc-d43568222a4564e22a6ffd370481e11ba031b318.tar.gz gcc-d43568222a4564e22a6ffd370481e11ba031b318.tar.bz2 |
PR tree-optimization/83239 - False positive from -Wstringop-overflow
PR tree-optimization/83239 - False positive from -Wstringop-overflow
on simple std::vector code
libstdc++/CHangeLog:
* include/bits/vector.tcc (vector::_M_default_append): Assert
invariant to generate better code.
gcc/testsuite/ChangeLog:
* g++.dg/pr83239.C: New test case.
From-SVN: r255753
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/pr83239.C | 56 |
2 files changed, 61 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 49c26ac..f16a187 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-12-16 Martin Sebor <msebor@redhat.com> + + PR tree-optimization/83239 + * g++.dg/pr83239.C: New test case. + 2017-12-16 Sebastian Peryt <sebastian.peryt@intel.com> PR testsuite/82767 diff --git a/gcc/testsuite/g++.dg/pr83239.C b/gcc/testsuite/g++.dg/pr83239.C new file mode 100644 index 0000000..b0f31be --- /dev/null +++ b/gcc/testsuite/g++.dg/pr83239.C @@ -0,0 +1,56 @@ +// PR tree-optimization/83239 - False positive from -Wstringop-overflow +// on simple std::vector code +// { dg-do compile } +// { dg-options "-O3 -Wall -fdump-tree-optimized" } + +#include <vector> + +// Verify no warnings are issued. + +template <class T> +void test_loop () +{ + std::vector<T> a; + + int num = 2; + + while (num > 0) + { + const typename std::vector<T>::size_type sz = a.size (); + + if (sz < 3) + a.assign (1, 0); + else + a.resize (sz - 2); + + --num; + } +} + +// Verify no warnings are issued here either. + +template <class T> +void test_if (std::vector<T> &a, int num) +{ + if (num > 0) + { + const typename std::vector<T>::size_type sz = a.size (); + + if (sz < 3) + a.assign (1, 0); + else + a.resize (sz - 2); + } +} + +// Instantiate each function on a different type to force both +// to be fully inlined. Instantiating both on the same type +// causes the inlining heuristics to outline _M_default_append +// which, in turn, masks the warning. +template void test_loop<int>(); +template void test_if<long>(std::vector<long>&, int); + +// Verify that std::vector<T>::_M_default_append() has been inlined +// (the absence of warnings depends on it). +// { dg-final { scan-tree-dump-not "_ZNSt6vectorIiSaIiEE17_M_default_appendEm" optimized } } +// { dg-final { scan-tree-dump-not "_ZNSt6vectorIPvSaIS0_EE17_M_default_appendEm" optimized } } |