public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/104165] [12 Regression] -Warray-bounds for unreachable code inlined from std::sort()
Date: Fri, 21 Jan 2022 17:16:43 +0000	[thread overview]
Message-ID: <bug-104165-4-OwllNl0O0V@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104165-4@http.gcc.gnu.org/bugzilla/>

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
                 CC|                            |msebor at gcc dot gnu.org
   Last reconfirmed|                            |2022-01-21
             Blocks|                            |56456
            Summary|[12 Regression] Incorrectly |[12 Regression]
                   |identifying array bounds    |-Warray-bounds for
                   |with -O2                    |unreachable code inlined
                   |-Werror=array-bounds        |from std::sort()
     Ever confirmed|0                           |1

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning triggers for the out of bounds pointer addition in &f.148 + 64 for
an array of 16 chars:

int foo (int n)
{
  unsigned char f.148[16];
  ...
  <bb 8> [local count: 116203857]:
  _25 = ASSERT_EXPR <_15, _15 != &f.148>;
  _6 = (signed long) _14;
  _19 = _6 /[ex] 4;
  __n.3_20 = (long unsigned int) _19;
  _21 = __builtin_clzl (__n.3_20);
  _22 = 63 - _21;
  _23 = (long int) _22;
  _24 = _23 * 2;
  std::__introsort_loop<int*, long int,
__gnu_cxx::__ops::_Iter_comp_iter<bar(int, int)::<lambda(int, int)> > >
(&f.148, _25, _24, __comp);
  if (_14 > 64)
    goto <bb 9>; [50.00%]
  else
    goto <bb 15>; [50.00%]

  <bb 9> [local count: 58101929]:
  std::__insertion_sort.constprop (&f.148, &MEM <int[0:D.48109]> [(void
*)&f.148 + 64B]);   <<< -Warray-bounds
  goto <bb 14>; [100.00%]

The basic block is removed later, in CCP3, as unreachable:

Removing basic block 8
;; basic block 8, loop depth 0
;;  pred:      
std::__insertion_sort.constprop (&f.148, &MEM <int[0:D.48109]> [(void *)&f.148
+ 64B]);
if (&MEM <int[0:D.48109]> [(void *)&f.148 + 64B] != _15)
  goto <bb 9>; [89.00%]
else
  goto <bb 13>; [11.00%]
;;  succ:       9
;;              13


The warning runs too early to benefit from the subsequent simplification.  This
is one instance of a false positive that something like __builtin_warning()
would cure.

GCC 11 emits (and eliminates) the same invalid expression but the warning is
suppressed because in GCC 11 -Warray-bounds wasn't issued code inlined from
system headers.  That's a GCC 12 change.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456
[Bug 56456] [meta-bug] bogus/missing -Warray-bounds

  parent reply	other threads:[~2022-01-21 17:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-21 15:40 [Bug c++/104165] New: Incorrectly identifying array bounds with -O2 -Werror=array-bounds kbrabml at gmail dot com
2022-01-21 17:04 ` [Bug tree-optimization/104165] [12 Regression] " pinskia at gcc dot gnu.org
2022-01-21 17:16 ` msebor at gcc dot gnu.org [this message]
2022-02-08 21:07 ` [Bug tree-optimization/104165] [12 Regression] -Warray-bounds for unreachable code inlined from std::sort() msebor at gcc dot gnu.org
2022-05-06  8:32 ` [Bug tree-optimization/104165] [12/13 " jakub at gcc dot gnu.org
2022-07-26 13:03 ` rguenth at gcc dot gnu.org
2022-12-05 15:39 ` [Bug tree-optimization/104165] [12 " rguenth at gcc dot gnu.org
2022-12-05 16:05 ` jakub at gcc dot gnu.org
2022-12-06  7:24 ` cvs-commit at gcc dot gnu.org
2022-12-06  7:29 ` rguenth at gcc dot gnu.org
2023-05-08 12:23 ` rguenth at gcc dot gnu.org
2023-09-27 12:36 ` fchelnokov at gmail dot com
2024-06-03 17:36 ` teodor_spaeren at riseup dot net
2024-06-03 18:09 ` xry111 at gcc dot gnu.org
2024-06-03 18:10 ` xry111 at gcc dot gnu.org
2024-06-20  9:01 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-104165-4-OwllNl0O0V@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).