public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114826] New: Bogus -Warray-bounds warning for 32-byte array with certain march flags
@ 2024-04-23 15:45 adam at adamrosenfield dot com
  2024-04-23 15:48 ` [Bug tree-optimization/114826] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: adam at adamrosenfield dot com @ 2024-04-23 15:45 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114826
           Summary: Bogus -Warray-bounds warning for 32-byte array with
                    certain march flags
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: adam at adamrosenfield dot com
  Target Milestone: ---

Sample code:

================== snip ==================
typedef long unsigned int size_t;
extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
       size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__
((__nonnull__ (1, 2)));
extern int memcmp (const void *__s1, const void *__s2, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__))
__attribute__ ((__nonnull__ (1, 2)));

int foo() {
    char dest[32] = {0};
    char src[32] = {0};

    memcpy(dest, src, 32);

    char expected[32] = {0};

    return memcmp(expected, dest, 32);
}
================== snip ==================

Compile as:

gcc -c test.c -Wall -march=haswell -O3

Output:

test.c: In function ‘foo’:
test.c:9:10: warning: array subscript ‘<unnamed-unsigned:256>[0]’ is partly
outside array bounds of ‘char[2]’ [-Warray-bounds=]
    9 |     char src[32] = {0};
      |          ^~~

This warning is clearly bogus, as there is no array of size 256 or size 2 here,
and there's no subscripting going on in this array declaration.

This occurs in GCC 13.2.0 and 13.1.0, but does not occur in GCC 12.x and
earlier.

This only occurs if the array size is exactly 32; other array sizes I've tried
do not trigger this.

This occurs with various different -march flags, including haswell, broadwell,
skylake, knl, knm, and many more of the *lake arches; it does not occur with
ivybridge and earlier.

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

* [Bug tree-optimization/114826] Bogus -Warray-bounds warning for 32-byte array with certain march flags
  2024-04-23 15:45 [Bug c/114826] New: Bogus -Warray-bounds warning for 32-byte array with certain march flags adam at adamrosenfield dot com
@ 2024-04-23 15:48 ` pinskia at gcc dot gnu.org
  2024-04-23 15:58 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-23 15:48 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |tree-optimization
             Blocks|                            |56456
           Keywords|                            |diagnostic

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Most likely the warning is due to the auto vectorizer.


Referenced Bugs:

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

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

* [Bug tree-optimization/114826] Bogus -Warray-bounds warning for 32-byte array with certain march flags
  2024-04-23 15:45 [Bug c/114826] New: Bogus -Warray-bounds warning for 32-byte array with certain march flags adam at adamrosenfield dot com
  2024-04-23 15:48 ` [Bug tree-optimization/114826] " pinskia at gcc dot gnu.org
@ 2024-04-23 15:58 ` rguenth at gcc dot gnu.org
  2024-04-23 17:35 ` [Bug tree-optimization/114826] [13 Regression] " pinskia at gcc dot gnu.org
  2024-04-23 17:36 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-23 15:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Rather store merging I guess.

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

* [Bug tree-optimization/114826] [13 Regression] Bogus -Warray-bounds warning for 32-byte array with certain march flags
  2024-04-23 15:45 [Bug c/114826] New: Bogus -Warray-bounds warning for 32-byte array with certain march flags adam at adamrosenfield dot com
  2024-04-23 15:48 ` [Bug tree-optimization/114826] " pinskia at gcc dot gnu.org
  2024-04-23 15:58 ` rguenth at gcc dot gnu.org
@ 2024-04-23 17:35 ` pinskia at gcc dot gnu.org
  2024-04-23 17:36 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-23 17:35 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Bogus -Warray-bounds        |[13 Regression] Bogus
                   |warning for 32-byte array   |-Warray-bounds warning for
                   |with certain march flags    |32-byte array with certain
                   |                            |march flags
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=113988
   Target Milestone|---                         |13.3

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #2)
> Rather store merging I guess.

Or rather how memcpy was done.

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

* [Bug tree-optimization/114826] [13 Regression] Bogus -Warray-bounds warning for 32-byte array with certain march flags
  2024-04-23 15:45 [Bug c/114826] New: Bogus -Warray-bounds warning for 32-byte array with certain march flags adam at adamrosenfield dot com
                   ` (2 preceding siblings ...)
  2024-04-23 17:35 ` [Bug tree-optimization/114826] [13 Regression] " pinskia at gcc dot gnu.org
@ 2024-04-23 17:36 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-23 17:36 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-04-23
     Ever confirmed|0                           |1

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This was fixed for the trunk by r14-9203 .

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

end of thread, other threads:[~2024-04-23 17:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-23 15:45 [Bug c/114826] New: Bogus -Warray-bounds warning for 32-byte array with certain march flags adam at adamrosenfield dot com
2024-04-23 15:48 ` [Bug tree-optimization/114826] " pinskia at gcc dot gnu.org
2024-04-23 15:58 ` rguenth at gcc dot gnu.org
2024-04-23 17:35 ` [Bug tree-optimization/114826] [13 Regression] " pinskia at gcc dot gnu.org
2024-04-23 17:36 ` pinskia 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).