public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sirl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/110458] New: -Warray-bounds=2 new false positive
Date: Wed, 28 Jun 2023 15:09:09 +0000	[thread overview]
Message-ID: <bug-110458-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110458
           Summary: -Warray-bounds=2 new false positive
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sirl at gcc dot gnu.org
  Target Milestone: ---

Created attachment 55412
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55412&action=edit
testcase

Since somewhere between r14-1870 and r14-2097 a new -Warray-bounds=2 false
positive is shown for this little testcase:

typedef struct {
  unsigned arr1[4];
  unsigned arr2[4];
} data;

void f_notok(void *arrayOut) {
  int i;
  unsigned *arr2;
  unsigned *arr1;
  data *dataOut;
  dataOut = (data *)arrayOut;
  arr1 = dataOut[0].arr1;
  arr2 = dataOut[0].arr2;
  i = 0;
  for (; i < 4; i++) {
    arr1[i] = 0;
    arr2[i] = 0;
  }
}

When compiled with trunk@r2097 "gcc -O2 -W -Wall -Warray-bounds=2 -c
bug-Warray-bounds-eq-2.c" the warning is:

bug-Warray-bounds-eq-2.c: In function 'f_notok':
bug-Warray-bounds-eq-2.c:16:13: warning: '__builtin_memset' offset [16, 31]
from the object at 'arrayOut' is out of the bounds of referenced subobject
'arr1' with type 'unsigned int[4]' at offset 0 [-Warray-bounds=]
   16 |     arr1[i] = 0;
      |     ~~~~~~~~^~~
bug-Warray-bounds-eq-2.c:2:12: note: subobject 'arr1' declared here
    2 |   unsigned arr1[4];
      |            ^~~~

gcc-13.1.1 and earlier didn't warn here. The attached full testcase also shows
that slight variations in the code silence the warning.

             reply	other threads:[~2023-06-28 15:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-28 15:09 sirl at gcc dot gnu.org [this message]
2023-06-28 19:21 ` [Bug tree-optimization/110458] " pinskia at gcc dot gnu.org
2023-06-29 10:13 ` sirl at gcc dot gnu.org
2023-06-29 15:54 ` [Bug tree-optimization/110458] [14 Regression] " pinskia at gcc dot gnu.org
2023-08-09  9:21 ` sirl at gcc dot gnu.org
2024-03-08 15:29 ` law at gcc dot gnu.org
2024-05-07  7:40 ` [Bug tree-optimization/110458] [14/15 " 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-110458-4@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).