public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: gcc@gcc.gnu.org
Subject: __attribute__ ((access, ...)) vs __attribute__ ((nonnull))
Date: Wed, 09 Mar 2022 16:23:48 -0500	[thread overview]
Message-ID: <2b899f7a1c9d9e57e1bb165405d8e57b1c86b889.camel@redhat.com> (raw)

We gained __attribute__ ((access, ...)) in GCC 10:
  https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
which identifies one of the pointer/reference arguments of a function
as being accessed according to an access-mode: read_only, read_write,
write_only, or none.

We also have __attribute__ ((nonnull)) to indicate that a function
argument (or all of them) must be non-NULL.

There doesn't seem to be a relationship between these in the
implementation, but it strikes me that almost anywhere that a user
might use the "access" attribute, that parameter is probably going to
be required to be nonnull - though perhaps there are cases where APIs
check for NULL and reject them gracefully?

Might we want to somehow make __attribute__ ((access, ...)) imply
__attribute__ ((nonnull))?  (for non "none" access modes, perhaps?)

If so, one place to implement this might be in tree.cc's
get_nonnull_args, and have it add to the bitmap any arguments that
have an appropriate access attribute.

get_nonnull_args is used in various places:
- validating builtins
- in ranger_cache::block_apply_nonnull
- by -Wnonnull (in pass_post_ipa_warn::execute)
- by -Wanalyzer-possible-null-argument and -Wanalyzer-null-argument;
I'm tracking the failure of these last two to make use of __attribute__
((access)) in PR analyzer/104860.

So do we:

(a) leave it up to the user, requiring them to specify __attribute__
((nonnull)) in addition to  __attribute__ ((access, ...))

(b) leave it up to the individual sites in GCC that currently make use
of get_nonnull_args to add logic for handling   __attribute__ ((access,
...))

(c) extend get_nonnull_args

?

Thoughts?
Dave


             reply	other threads:[~2022-03-09 21:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-09 21:23 David Malcolm [this message]
2022-03-09 21:30 ` Andrew Pinski
2022-03-09 21:57   ` [PATCH] Document that the 'access' and 'nonnull' attributes are independent David Malcolm
2022-03-14 22:18     ` Martin Sebor
2022-03-23 13:01       ` [PATCH v2] " David Malcolm
2022-03-23 16:31         ` Martin Sebor
2022-03-23 16:52           ` Sebastian Huber
2022-03-25 18:45             ` [PATCH v3] " David Malcolm
2022-03-25 20:38               ` Martin Sebor
2022-04-05 20:46                 ` David Malcolm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b899f7a1c9d9e57e1bb165405d8e57b1c86b889.camel@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).