summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-01-13 16:47:55 +0300
committerSimon Glass <sjg@chromium.org>2022-01-13 19:13:41 +0300
commit78aac05eb1de0f70f7643a575ff543211d2cc6f4 (patch)
tree419f00d1f33daacb1907a85ebcb2b100a23a12cb /include/linux
parent5ecdd529ae38fecd35bfc41869058802c804a01e (diff)
downloadu-boot-78aac05eb1de0f70f7643a575ff543211d2cc6f4.tar.xz
stddef: Avoid warning with clang with offsetof()
Some bright sparks have decided that a cast on a constant cannot be a constant, so offsetof() produces this warning on clang-10: include/intel_gnvs.h:113:1: error: static_assert expression is not an integral constant expression check_member(acpi_global_nvs, unused2, GNVS_CHROMEOS_ACPI_OFFSET); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/kernel.h:284:2: note: expanded from macro 'check_member' offsetof(struct structure, member) == (offset), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/stddef.h:20:32: note: expanded from macro 'offsetof' ^ include/intel_gnvs.h:113:1: note: cast that performs the conversions of a reinterpret_cast is ot allowed in a constant expression include/linux/stddef.h:20:33: note: expanded from macro 'offsetof' Fix it by using the compiler built-in version, if available. This syncs the function to the same implementation as Linux v5.16 in this header file. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/stddef.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index c540f6100d..a7f546fdfe 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -1,6 +1,8 @@
#ifndef _LINUX_STDDEF_H
#define _LINUX_STDDEF_H
+#include <linux/compiler_types.h>
+
#undef NULL
#if defined(__cplusplus)
#define NULL 0
@@ -14,7 +16,11 @@
#ifndef __CHECKER__
#undef offsetof
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#ifdef __compiler_offsetof
+#define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER)
+#else
+#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
+#endif
#endif
#endif