public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110458] New: -Warray-bounds=2 new false positive
@ 2023-06-28 15:09 sirl at gcc dot gnu.org
  2023-06-28 19:21 ` [Bug tree-optimization/110458] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: sirl at gcc dot gnu.org @ 2023-06-28 15:09 UTC (permalink / raw)
  To: gcc-bugs

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.

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

end of thread, other threads:[~2024-05-07  7:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-28 15:09 [Bug c/110458] New: -Warray-bounds=2 new false positive sirl at gcc dot gnu.org
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

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).