public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/107986] New: [12/13 Regression] Bogus -Warray-bounds diagnostic with std::sort
@ 2022-12-06  7:28 rguenth at gcc dot gnu.org
  2022-12-06  7:28 ` [Bug tree-optimization/107986] " rguenth at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-06  7:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107986
           Summary: [12/13 Regression] Bogus -Warray-bounds diagnostic
                    with std::sort
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

PR104165 comment 2 talks about a test case reduced in
https://bugzilla.redhat.com/show_bug.cgi?id=2051783:

#include <algorithm>

bool cond;
int foo;

int func (void)
{
  int a[3], qa = 0;
  for(int i = 0; i < 3; i++)
    if (cond)
      a[qa++] = foo;

  std::sort (a, a + qa);
  return 0;
}

which still warns with both GCC 12 and 13 at -O2 -Wall like

In file included from
/home/rguenther/install/gcc-13/usr/local/include/c++/13.0.0/algorithm:61,
                 from t.C:1:
In function 'void std::__final_insertion_sort(_RandomAccessIterator,
_RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare =
__gnu_cxx::__ops::_Iter_less_iter]',
    inlined from 'void std::__final_insertion_sort(_RandomAccessIterator,
_RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare =
__gnu_cxx::__ops::_Iter_less_iter]' at
/home/rguenther/install/gcc-13/usr/local/include/c++/13.0.0/bits/stl_algo.h:1854:5,
    inlined from 'void std::__sort(_RandomAccessIterator,
_RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare =
__gnu_cxx::__ops::_Iter_less_iter]' at
/home/rguenther/install/gcc-13/usr/local/include/c++/13.0.0/bits/stl_algo.h:1950:31,
    inlined from 'void std::__sort(_RandomAccessIterator,
_RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare =
__gnu_cxx::__ops::_Iter_less_iter]' at
/home/rguenther/install/gcc-13/usr/local/include/c++/13.0.0/bits/stl_algo.h:1942:5,
    inlined from 'void std::sort(_RAIter, _RAIter) [with _RAIter = int*]' at
/home/rguenther/install/gcc-13/usr/local/include/c++/13.0.0/bits/stl_algo.h:4860:1,
    inlined from 'int func()' at t.C:13:13:
/home/rguenther/install/gcc-13/usr/local/include/c++/13.0.0/bits/stl_algo.h:1859:32:
warning: array subscript 16 is outside array bounds of 'int [3]'
[-Warray-bounds=]
 1859 |           std::__insertion_sort(__first, __first + int(_S_threshold),
__comp);
      |          
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t.C: In function 'int func()':
t.C:8:7: note: at offset 64 into object 'a' of size 12
    8 |   int a[3], qa = 0;
      |       ^

I'll also note the lack of a non-included location in t.C.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-06-20  9:11 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06  7:28 [Bug tree-optimization/107986] New: [12/13 Regression] Bogus -Warray-bounds diagnostic with std::sort rguenth at gcc dot gnu.org
2022-12-06  7:28 ` [Bug tree-optimization/107986] " rguenth at gcc dot gnu.org
2022-12-06  7:43 ` rguenth at gcc dot gnu.org
2022-12-06  7:51 ` pinskia at gcc dot gnu.org
2022-12-06  7:53 ` rguenth at gcc dot gnu.org
2022-12-06  7:55 ` rguenth at gcc dot gnu.org
2022-12-06  9:38 ` jakub at gcc dot gnu.org
2022-12-06  9:47 ` rguenther at suse dot de
2022-12-06  9:54 ` rguenth at gcc dot gnu.org
2022-12-07 17:12 ` amacleod at redhat dot com
2023-05-08 12:26 ` [Bug tree-optimization/107986] [12/13/14 " rguenth at gcc dot gnu.org
2023-05-24 21:19 ` cvs-commit at gcc dot gnu.org
2023-09-28  7:45 ` asharafutdinov at adalisk dot com
2023-12-15 13:45 ` rguenth at gcc dot gnu.org
2024-06-03 18:26 ` [Bug tree-optimization/107986] [12/13/14/15 " teodor_spaeren at riseup dot net
2024-06-20  9:11 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).