Bug 97495 - -Wstringop-overflow where -Warray-bounds would be more appropriate
Summary: -Wstringop-overflow where -Warray-bounds would be more appropriate
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Warray-bounds Wstringop-overflow
  Show dependency treegraph
 
Reported: 2020-10-19 16:06 UTC by Martin Sebor
Modified: 2021-09-26 07:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-09-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2020-10-19 16:06:43 UTC
-Wstringop-overflow is documented to "Warn for calls to string manipulation functions such as memcpy and strcpy that are determined to overflow the destination buffer" but in GCC 11 it's issued even for user-defined functions that don't manipulate strings.  GCC should issue -Warray-bounds for those instead.  In addition, mentioning array indices rather than byte counts might make the warnings easier to interpret.

$ cat z.c && gcc -O2 -S -Wall z.c
void f (int[static 4]);

void g (void)
{
  int a[2];
  f (a);
}
  
z.c: In function ‘g’:
z.c:6:3: warning: ‘f’ accessing 16 bytes in a region of size 8 [-Wstringop-overflow=]
    6 |   f (a);
      |   ^~~~~
z.c:6:3: note: referencing argument 1 of type ‘int *’
z.c:1:6: note: in a call to function ‘f’
    1 | void f (int[static 4]);
      |      ^


Clang issues -Warray-bounds as expected:

z.c:6:3: warning: array argument is too small; contains 2 elements, callee
      requires at least 4 [-Warray-bounds]
  f (a);
  ^  ~
z.c:1:12: note: callee declares array parameter as static here
void f (int[static 4]);
           ^~~~~~~~~~
1 warning generated.
Comment 1 Martin Sebor 2020-10-19 16:07:47 UTC
Confirmed on Mark's behalf (CC'd).