From 84a95741805d84f0074a34d61b93ccf86f422cf3 Mon Sep 17 00:00:00 2001 From: Hans Rosenfeld Date: Thu, 16 Apr 2026 20:22:44 +0200 Subject: [PATCH] sys/cdefs.h: Introduce __maybe_unused attribute The __maybe_unused attribute should be used for variables which may or may not be used, such as when their only use is in an assertion. This attribute is functionally identical to __unused, suppressing compiler warnings for particular variable if it remains unused. Reviewed by: Minsoo Choo , imp Differential Revision: https://reviews.freebsd.org/D56517 --- share/man/man9/cdefs.9 | 6 ++++-- .../linuxkpi/common/include/linux/compiler_attributes.h | 1 - sys/sys/cdefs.h | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/share/man/man9/cdefs.9 b/share/man/man9/cdefs.9 index cc56e34d070..2bda50c3f87 100644 --- a/share/man/man9/cdefs.9 +++ b/share/man/man9/cdefs.9 @@ -3,7 +3,7 @@ .\" .\" SPDX-License-Identifier: BSD-2-Clause .\" -.Dd May 9, 2025 +.Dd May 6, 2026 .Dt CDEFS 9 .Os .Sh NAME @@ -85,7 +85,9 @@ linkage. .It Sy __weak_symbol Ta Declare the symbol to be a weak symbol .It Sy __dead2 Ta Function will not return .It Sy __pure2 Ta Function has no side effects -.It Sy __unused Ta To Variable may be unused (usually arguments), so do not +.It Sy __unused Ta Variable may be unused (usually arguments), so do not +warn about it +.It Sy __maybe_unused Ta Variable may be unused (usually arguments), so do not warn about it .It Sy __used Ta Function really is used, so emit it even if it appears unused. .It Sy __deprecated Ta Function interface has been deprecated, and clients diff --git a/sys/compat/linuxkpi/common/include/linux/compiler_attributes.h b/sys/compat/linuxkpi/common/include/linux/compiler_attributes.h index 42908bb6c2b..159c833802c 100644 --- a/sys/compat/linuxkpi/common/include/linux/compiler_attributes.h +++ b/sys/compat/linuxkpi/common/include/linux/compiler_attributes.h @@ -39,7 +39,6 @@ #define noinline_for_stack __noinline -#define __maybe_unused __unused #define __always_unused __unused #define __must_check __result_use_check diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index 132d4809b0e..a08c50c8439 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -152,6 +152,7 @@ #define __weak_symbol __attribute__((__weak__)) #define __dead2 __attribute__((__noreturn__)) #define __pure2 __attribute__((__const__)) +#define __maybe_unused __attribute__((__unused__)) #define __unused __attribute__((__unused__)) #define __used __attribute__((__used__)) #define __deprecated __attribute__((__deprecated__))