All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>
Subject: [PATCH v2 01/12] stddef: Avoid warning with clang with offsetof()
Date: Wed, 12 Jan 2022 19:26:14 -0700	[thread overview]
Message-ID: <20220113022625.413990-2-sjg@chromium.org> (raw)
In-Reply-To: <20220113022625.413990-1-sjg@chromium.org>

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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 include/linux/stddef.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index c540f6100d4..a7f546fdfe5 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
-- 
2.34.1.575.g55b058a8bb-goog


  reply	other threads:[~2022-01-13  2:26 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13  2:26 [PATCH v2 00/12] bloblist: Enhancements for standard passage Simon Glass
2022-01-13  2:26 ` Simon Glass [this message]
2022-01-13  2:26 ` [PATCH v2 02/12] fdt: Drop SPL_BUILD macro Simon Glass
2022-01-13  2:26 ` [PATCH v2 03/12] bloblist: Put the magic number first Simon Glass
2022-01-13  2:26 ` [PATCH v2 04/12] bloblist: Rename the SPL tag Simon Glass
2022-01-13  2:26 ` [PATCH v2 05/12] bloblist: Drop unused tags Simon Glass
2022-01-13  2:26 ` [PATCH v2 06/12] bloblist: Use explicit numbering for the tags Simon Glass
2022-01-13  2:26 ` [PATCH v2 07/12] bloblist: Use LOG_CATEGORY to simply logging Simon Glass
2022-01-13  2:26 ` [PATCH v2 08/12] bloblist: Use 'phase' consistently for bloblists Simon Glass
2022-01-13  2:26 ` [PATCH v2 09/12] bloblist: Refactor Kconfig to support alloc or fixed Simon Glass
2022-01-13  2:26 ` [PATCH v2 10/12] bloblist: Add functions to obtain base address and size Simon Glass
2022-01-13  2:26 ` [PATCH v2 11/12] bloblist: doc: Bring in the API documentation Simon Glass
2022-01-13  2:26 ` [PATCH v2 12/12] bloblist: Relicense to allow BSD-3-Clause Simon Glass
2022-01-13 18:00 ` Simon Glass
2022-01-13 18:00 ` [PATCH v2 11/12] bloblist: doc: Bring in the API documentation Simon Glass
2022-01-13 18:00 ` [PATCH v2 10/12] bloblist: Add functions to obtain base address and size Simon Glass
2022-01-13 18:00 ` [PATCH v2 08/12] bloblist: Use 'phase' consistently for bloblists Simon Glass
2022-01-13 18:00 ` [PATCH v2 09/12] bloblist: Refactor Kconfig to support alloc or fixed Simon Glass
2022-01-13 18:00 ` [PATCH v2 06/12] bloblist: Use explicit numbering for the tags Simon Glass
2022-01-13 18:00 ` [PATCH v2 07/12] bloblist: Use LOG_CATEGORY to simply logging Simon Glass
2022-01-13 18:00 ` [PATCH v2 05/12] bloblist: Drop unused tags Simon Glass
2022-01-13 18:00 ` [PATCH v2 04/12] bloblist: Rename the SPL tag Simon Glass
2022-01-13 18:00 ` [PATCH v2 03/12] bloblist: Put the magic number first Simon Glass
2022-01-13 18:00 ` [PATCH v2 02/12] fdt: Drop SPL_BUILD macro Simon Glass

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=20220113022625.413990-2-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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.