public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH 1/2] Compiler Attributes: Add __access macro
@ 2026-04-21 19:03 Marco Elver
  2026-04-21 19:03 ` [PATCH 2/2] kcsan: Silence -Wmaybe-uninitialized when calling __kcsan_check_access() Marco Elver
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Marco Elver @ 2026-04-21 19:03 UTC (permalink / raw)
  To: elver
  Cc: kasan-dev, linux-kernel, Arnd Bergmann, Miguel Ojeda,
	Dmitry Vyukov, Nathan Chancellor, llvm

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
+
 /*
  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alias-function-attribute
  */
-- 
2.54.0.rc2.533.g4f5dca5207-goog


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-04-22 13:22 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox