From: Uros Bizjak <ubizjak@gmail.com>
To: x86@kernel.org, linux-sparse@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org,
linux-arch@vger.kernel.org, netdev@vger.kernel.org
Cc: Uros Bizjak <ubizjak@gmail.com>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
Christoph Lameter <cl@linux.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Andy Lutomirski <luto@kernel.org>, Ingo Molnar <mingo@kernel.org>,
Nadav Amit <nadav.amit@gmail.com>,
Brian Gerst <brgerst@gmail.com>,
Denys Vlasenko <dvlasenk@redhat.com>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH 2/6] compiler.h: Introduce TYPEOF_UNQUAL() macro
Date: Tue, 26 Nov 2024 18:21:19 +0100 [thread overview]
Message-ID: <20241126172332.112212-3-ubizjak@gmail.com> (raw)
In-Reply-To: <20241126172332.112212-1-ubizjak@gmail.com>
Define TYPEOF_UNQUAL() to use __typeof_unqual__() as typeof operator
when available, to return unqualified type of the expression.
Current version of sparse doesn't know anything about __typeof_unqual__()
operator. Avoid the usage of __typeof_unqual__() when sparse checking
is active to prevent sparse errors with unknowing keyword.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Nadav Amit <nadav.amit@gmail.com>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org
---
include/linux/compiler.h | 13 +++++++++++++
init/Kconfig | 3 +++
2 files changed, 16 insertions(+)
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 469a64dd6495..bb0bde335129 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -321,6 +321,19 @@ static inline void *offset_to_ptr(const int *off)
*/
#define prevent_tail_call_optimization() mb()
+/*
+ * Define unqual_typeof() to use __typeof_unqual__() as typeof
+ * operator when available, to return unqualified type of the exp.
+ *
+ * XXX: Remove test for __CHECKER__ once
+ * sparse learns about __typeof_unqual__.
+ */
+#if defined(CONFIG_CC_HAS_TYPEOF_UNQUAL) && !defined(__CHECKER__)
+# define TYPEOF_UNQUAL(exp) __typeof_unqual__(exp)
+#else
+# define TYPEOF_UNQUAL(exp) __typeof__(exp)
+#endif
+
#include <asm/rwonce.h>
#endif /* __LINUX_COMPILER_H */
diff --git a/init/Kconfig b/init/Kconfig
index a20e6efd3f0f..c1f9eb3d5f2e 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -894,6 +894,9 @@ config ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
config CC_HAS_INT128
def_bool !$(cc-option,$(m64-flag) -D__SIZEOF_INT128__=0) && 64BIT
+config CC_HAS_TYPEOF_UNQUAL
+ def_bool $(success,echo 'int foo (int a) { __typeof_unqual__(a) b = a; return b; }' | $(CC) -x c - -S -o /dev/null)
+
config CC_IMPLICIT_FALLTHROUGH
string
default "-Wimplicit-fallthrough=5" if CC_IS_GCC && $(cc-option,-Wimplicit-fallthrough=5)
--
2.42.0
next prev parent reply other threads:[~2024-11-26 17:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-26 17:21 [PATCH 0/6] Enable strict percpu address space checks Uros Bizjak
2024-11-26 17:21 ` [PATCH 1/6] x86/kgdb: Use IS_ERR_PCPU() macro Uros Bizjak
2024-11-26 17:21 ` Uros Bizjak [this message]
2024-11-26 17:21 ` [PATCH 3/6] percpu: Use TYPEOF_UNQUAL() in variable declarations Uros Bizjak
2024-11-26 17:21 ` [PATCH 4/6] percpu: Use TYPEOF_UNQUAL() in *_cpu_ptr() accessors Uros Bizjak
2024-11-26 17:21 ` [PATCH 5/6] percpu: Repurpose __percpu tag as a named address space qualifier Uros Bizjak
2024-11-26 17:21 ` [PATCH 6/6] percpu/x86: Enable strict percpu checks via named AS qualifiers Uros Bizjak
2024-11-29 15:45 ` Nadav Amit
2024-11-29 16:33 ` Uros Bizjak
2024-12-04 7:24 ` [PATCH 0/6] Enable strict percpu address space checks Dan Carpenter
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=20241126172332.112212-3-ubizjak@gmail.com \
--to=ubizjak@gmail.com \
--cc=brgerst@gmail.com \
--cc=cl@linux.com \
--cc=dennis@kernel.org \
--cc=dvlasenk@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-bcachefs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-sparse@vger.kernel.org \
--cc=luc.vanoostenryck@gmail.com \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=nadav.amit@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox