On 8/2/2021 3:44 PM, Martin Sebor via Gcc-patches wrote:
The write_only mode to attribute access specifies that the pointer
applies to is used to write to the referenced object but not read
from it.

A function that uses the pointer to read the referenced object might rely on the contents of uninitialized memory and so such attempts
should be diagnosed.  The attached enhancement makes that happen.
It was tested on x86_64-linux and by building Glibc where it found
an inappropriate use of the attribute on a function documented to
read from the argument as an extension [BZ 28170].

I plan to implement a similar warning for writes to read-only objects
(either with attribute read_only, or those declared const, or const
restrict) pointers in a followup (as part of my solution for PR 90404).

Martin

BZ 28170: https://sourceware.org/bugzilla/show_bug.cgi?id=28170

gcc-101374.diff

Warn for reads from write-only arguments [PR101734].

Resolves:
PR middle-end/101734 - missing warning reading from a write-only object

gcc/ChangeLog:

        PR middle-end/101734
        * tree-ssa-uninit.c (maybe_warn_read_write_only): New function.
        (maybe_warn_operand): Call it.

gcc/testsuite/ChangeLog:

        PR middle-end/101734
        * gcc.dg/uninit-42.c: New test.
OK
jeff

Reply via email to