Bug 99676 - missing detail in warning for passing smaller array to bigger argument
Summary: missing detail in warning for passing smaller array to bigger argument
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 11.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wstringop-overflow
  Show dependency treegraph
 
Reported: 2021-03-19 22:22 UTC by Martin Sebor
Modified: 2021-03-19 22:23 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2021-03-19 22:22:16 UTC
The warning(s) below are confusing:
1) each mentions the argument type is 'int *' when it actually uses 'int[4]' to trigger, and
2) it doesn't point to the declaration of the object or subobject whose size it uses.
In cases like pr99673 the missing details make the warning harder than necessary to understand and decide if it's a false positive.

$ cat x.c && gcc -O -S -Wall x.c
struct A { int a[2], b[2]; };

void f (int[4], int[4]);

void g (int *p, int *q)
{
  f (p, q);
}

void h (struct A *p)
{
  g (p->a, p->b);
}
In function ‘g’,
    inlined from ‘h’ at x.c:12:3:
x.c:7:3: warning: ‘f’ accessing 16 bytes in a region of size 8 [-Wstringop-overflow=]
    7 |   f (p, q);
      |   ^~~~~~~~
x.c: In function ‘h’:
x.c:7:3: note: referencing argument 1 of type ‘int *’
In function ‘g’,
    inlined from ‘h’ at x.c:12:3:
x.c:7:3: warning: ‘f’ accessing 16 bytes in a region of size 8 [-Wstringop-overflow=]
x.c: In function ‘h’:
x.c:7:3: note: referencing argument 2 of type ‘int *’
x.c:3:6: note: in a call to function ‘f’
    3 | void f (int[4], int[4]);
      |      ^
Comment 1 Martin Sebor 2021-03-19 22:23:55 UTC
The warning should also not be -Wstringop-overflow or -Wstringop-overread (which are meant to be about accesses by functions declared in <string.h> and maybe also direct string accesses by pointers) but probably -Warray-bounds.