All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Marco Elver <elver@google.com>
Cc: kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org,
	Arnd Bergmann <arnd@arndb.de>, Miguel Ojeda <ojeda@kernel.org>,
	Dmitry Vyukov <dvyukov@google.com>,
	Nathan Chancellor <nathan@kernel.org>,
	llvm@lists.linux.dev
Subject: Re: [PATCH 1/2] Compiler Attributes: Add __access macro
Date: Wed, 22 Apr 2026 11:01:14 +0100	[thread overview]
Message-ID: <20260422110114.0f48d109@pumpkin> (raw)
In-Reply-To: <20260421190351.1976329-1-elver@google.com>

On Tue, 21 Apr 2026 21:03:47 +0200
Marco Elver <elver@google.com> wrote:

> Add support for the `__access__` attribute, which is supported since gcc
> >= 11 but not currently supported by clang.  
> 
> The attribute allows specifying how a function accesses memory passed
> via a pointer argument (read_only, write_only, read_write, none) and
> optionally the size of the access. Per [1] these annotations only affect
> diagnostics, and should not affect code generation:
> 
> 	"The access attribute enables the detection of invalid or unsafe
> 	 accesses by functions or their callers, as well as write-only
> 	 accesses to objects that are never read from. Such accesses may
> 	 be diagnosed by warnings such as -Wstringop-overflow,
> 	 -Wuninitialized, -Wunused, and others."
> 
> [1] https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-access
> 
> Signed-off-by: Marco Elver <elver@google.com>
> ---
>  include/linux/compiler_attributes.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h
> index c16d4199bf92..ef4e279e9872 100644
> --- a/include/linux/compiler_attributes.h
> +++ b/include/linux/compiler_attributes.h
> @@ -20,6 +20,18 @@
>   * Provide links to the documentation of each supported compiler, if it exists.
>   */
>  
> +/*
> + * Optional: only supported since gcc >= 11
> + * Optional: not supported by clang
> + *
> + *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-access
> + */
> +#if __has_attribute(__access__)
> +# define __access(x, ...)		__attribute__((__access__(x, ## __VA_ARGS__)))
> +#else
> +# define __access(x, ...)
> +#endif

No need to the initial 'x', you can just do:
# define __access(...)		__attribute__((__access__(__VA_ARGS__)))

Putting the actual syntax in the comment would help, eg as:
	__access__(read_only|read_write|write_only|none, param_number[, size])

	David

> +
>  /*
>   *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alias-function-attribute
>   */


  parent reply	other threads:[~2026-04-22 10:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-21 19:03 [PATCH 1/2] Compiler Attributes: Add __access macro Marco Elver
2026-04-21 19:03 ` [PATCH 2/2] kcsan: Silence -Wmaybe-uninitialized when calling __kcsan_check_access() Marco Elver
2026-04-21 19:15 ` [PATCH 1/2] Compiler Attributes: Add __access macro Miguel Ojeda
2026-04-21 19:20   ` Marco Elver
2026-04-21 19:30     ` Arnd Bergmann
2026-04-21 19:35       ` Marco Elver
2026-04-22 10:25       ` Miguel Ojeda
2026-04-22 10:30         ` Miguel Ojeda
2026-04-22 13:22         ` David Laight
2026-04-22  5:50 ` Nathan Chancellor
2026-04-22 10:01 ` David Laight [this message]
2026-04-22 10:20   ` Marco Elver
2026-04-22 13:06     ` Marco Elver
2026-04-22 10:25   ` Miguel Ojeda
2026-04-22 13:02     ` David Laight

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=20260422110114.0f48d109@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=arnd@arndb.de \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ojeda@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.