On 11/24/2021 7:16 PM, Martin Sebor via Gcc-patches wrote:
When the optional size-index argument to attribute index is
omitted for a pointer, GCC expects the actual pointer argument
to point to an object at least as big as its size implies, or
at least one byte for void*.  This is done to make it possible
to detect past-the-end accesses in calls to functions that
only take a pointer (and not a size).

This logic has proved to be overly restrictive for the "none"
access mode applied to void* pointer arguments as a signal
that a function doesn't access the object.  The use case that
brought this to light is a function that only stores its pointer
argument somewhere for later use, without ever dereferencing it,
like pthread_setspecific() does.  pthread_setspecific() needs to
use attribute access because it takes a const void* argument,
and GCC assumes that functions with const-qualified pointer
arguments read from the memory they point to (as most do) and
issues -Wuninitialized when it detects the object such a pointer
points to is not initialized.

The attached tweak adjusts the logic to exempt void* arguments
with access none from the usual bounds checking by setting
the expected object size to zero.  This lets Glibc to continue
to annotate pthread_setspecific() with attribute access none
in its headers to avoid the -Wuninitialized in user code.

Tested on x86_64-linux.

Martin

gcc-101751.diff

Avoid expecting nonzero size for access none void* arguments [PR101751].

Resolves:
PR middle-end/101751 - attribute access none with void pointer expects nonzero 
size

gcc/ChangeLog:

        PR middle-end/101751
        * doc/invoke.texi (attribute access): Adjust.
        * gimple-ssa-warn-access.cc (pass_waccess::maybe_check_access_sizes):

gcc/testsuite/ChangeLog:

        PR middle-end/101751
        * gcc.dg/Wstringop-overflow-86.c: New test.
OK
jeff

Reply via email to