https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96505
Bug ID: 96505
Summary: attribute access effect lost after inlining
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
CC: marxin at gcc dot gnu.org
Target Milestone: ---
Prompted by the discussion at
https://gcc.gnu.org/pipermail/gcc-patches/2020-August/551526.html, the
following test case shows that the effect of attribute access is lost after a
function declared with it has been inlined. This makes the attribute next to
useless in code like libstdc++ that makes heavy use of inlining and/or
templates.
See also pr96502 and pr96503 for similar problems involving other function
attributes. I've raised these as separate issues because I expect each to need
a different solution.
$ cat x.c && gcc -O2 -S -Wall -Wextra x.c
void f (void*, int);
__attribute__ ((access (write_only, 1, 2), noinline)) void
f0 (void *p, int n) { f (p, n); }
void h0 (void)
{
char a[3];
f0 (a, 5); // warning (good)
}
__attribute__ ((access (write_only, 1, 2))) void
f1 (void *p, int n) { f (p, n); }
void h1 (void)
{
char a[3];
f1 (a, 5); // missing warning
}
x.c: In function ‘h0’:
x.c:9:3: warning: ‘f0’ writing 5 bytes into a region of size 3 overflows the
destination [-Wstringop-overflow=]
9 | f0 (a, 5); // warning (good)
| ^~~~~~~~~
x.c:4:2: note: in a call to function ‘f0’ declared with attribute ‘write_only
(1, 2)’
4 | f0 (void *p, int n) { f (p, n); }
| ^~