https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101734
Bug ID: 101734
Summary: missing warning reading from a write-only object
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
The write_only mode to attribute access is documented like so:
The write_only access mode applies to arguments of pointer types without the
const qualifier. It specifies that the pointer to which it applies is used to
write to the referenced object but not read from it.
A function that uses the pointer to read the refdrenced object might rely on
the contents of uninitialized memory and so such attempts should be diagnosed.
GCC 11 (and 12) fails to do so:
$ cat z.c && gcc -O2 -S -Wall z.c
__attribute__ ((access (write_only, 1, 2)))
int f (int *p, int n)
{
return *p;
}
$
The same goes for attribute none.