From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 263BAC433EF for ; Thu, 13 Jan 2022 13:07:44 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9808A832DA; Thu, 13 Jan 2022 14:07:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=konsulko.com header.i=@konsulko.com header.b="iEn6vA4O"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D23A6832E3; Thu, 13 Jan 2022 14:07:40 +0100 (CET) Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DDAEF831F0 for ; Thu, 13 Jan 2022 14:07:37 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=trini@konsulko.com Received: by mail-qv1-xf2d.google.com with SMTP id q3so6518204qvc.7 for ; Thu, 13 Jan 2022 05:07:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=bYSm5XqxHiOqt6V0GVc2lNr4jxIP0XLBasFKUE4Bg4s=; b=iEn6vA4OUG/nGwdcbTDN42dL/nJZxZ6fWQ7ZTldNflKKDOR0HydG04PuWqcmaOQABm 9ZCj6UvwzznwqfhUdrYDS8JIe2ciWdnfZ6qP+0UekoCLeNGiUm+N8BqGlT5uorUx33Wb VZKyMmwRGB+wGfPRxjoubvoup8Qlgt2r0GGB8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=bYSm5XqxHiOqt6V0GVc2lNr4jxIP0XLBasFKUE4Bg4s=; b=ioAl+lZ2mueFCsNknEadINWIhPmtS/aKXAlH0Juy5y0lVTPRYil9QSEC5BUBuQqA29 cH6ZFBwpooYc8UNLhi3+F3ppx0sL99FZA35HWezVe1jvOHDWhKaRpmNQX87klz0B00Hb vsN0PqTvtwZ/bCh/c803SBSDw8Uxqso0csIRjhm9/AzY39buYzYjzn/p2KpSEqv5525O /DwjYfCp7F4af8FhTfYD1LQDi/5UU8JFjPrH2cdqvKNotvhJHGRlaotvsSQ4R+Fwpsfe 5fCRmaAg0hVzzfoviw6WAq8aFhNcB9Dm81S0wVxsnEW1rFrVL0zU5SUMu9iLtUYOd/x1 5OcA== X-Gm-Message-State: AOAM530aKpa1rHFLRsFXYErRSSoPnSMjNMCStk3Qvi8ku/e2dTr7UjeT ChDynuNx32intOfFI1wNkovZPcHbOThP9Q== X-Google-Smtp-Source: ABdhPJwTV6Ycffzx7cEfZrDyzeyJ77YJ/U2gbbRIKuvW/Jda/6s6AtdvOfq4FvQb/VrWTdnmN7LSGA== X-Received: by 2002:a05:6214:2aaa:: with SMTP id js10mr51670qvb.115.1642079256676; Thu, 13 Jan 2022 05:07:36 -0800 (PST) Received: from bill-the-cat (2603-6081-7b01-cbda-2440-966a-5ce3-c6d0.res6.spectrum.com. [2603:6081:7b01:cbda:2440:966a:5ce3:c6d0]) by smtp.gmail.com with ESMTPSA id w14sm1946234qta.6.2022.01.13.05.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jan 2022 05:07:36 -0800 (PST) Date: Thu, 13 Jan 2022 08:07:34 -0500 From: Tom Rini To: Rasmus Villemoes Cc: Simon Glass , U-Boot Mailing List , Bin Meng , Ilias Apalodimas , Bill Mills , Heinrich Schuchardt , =?iso-8859-1?Q?Fran=E7ois?= Ozog Subject: Re: [PATCH 04/31] stddef: Avoid warning with clang with offsetof() Message-ID: <20220113130734.GJ9207@bill-the-cat> References: <20211101011734.1614781-1-sjg@chromium.org> <20211101011734.1614781-5-sjg@chromium.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="E0LdhqWfziiBVv4P" Content-Disposition: inline In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean --E0LdhqWfziiBVv4P Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jan 13, 2022 at 09:08:13AM +0100, Rasmus Villemoes wrote: > On 01/11/2021 02.17, Simon Glass wrote: > > Some bright sparks have decided that a cast on a constant cannot be a > > constant, so offsetof() produces this warning on clang-10: > >=20 > > 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) =3D=3D (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' > >=20 > > Fix it by using the compiler built-in version, if available. > >=20 > > Signed-off-by: Simon Glass > > --- > >=20 > > include/linux/stddef.h | 8 +++++++- > > 1 file changed, 7 insertions(+), 1 deletion(-) > >=20 > > 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 > > =20 > > +#include > > + > > #undef NULL > > #if defined(__cplusplus) > > #define NULL 0 > > @@ -14,7 +16,11 @@ > > =20 > > #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 >=20 >=20 > Can we please just drop the useless indirections? Any compiler we care > about provides __builtin_offsetof(), so just make the whole thing >=20 > #undef offsetof > #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) >=20 > And by "compilers we care about", that includes sparse - it has had > __builtin_offsetof ever since 2007. >=20 > And we can nuke the __compiler_offsetof definition in compiler_types.h, > and if any users exist, just mechanically convert them to offsetof(). We should re-sync this with upstream, but that will keep the indirection you're objecting to here, I think. --=20 Tom --E0LdhqWfziiBVv4P Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmHgJBIACgkQFHw5/5Y0 tyw6rgwAjgxCwl90vqFTED0W//nlPU+2PLMj3Zb9ACoADi8ASfOGO06yuHyEziRD ZJMf8UX/BelWkBHTbbWOrW8feXEiJhYFlAOBVh7YVCzfdr8Q2A7H8vIqj00MGGR7 xxfyxSAb9NJYUwzTHrZrdw0Q/CaCoIZ74rfchS+GYEo6gMZFBSK83xnpwn/fRQnP M93tvs6RmZOBkgbKLmfsW9yr5YCMzotwlbUNowIDqoiqPj2oPwDB5Ijp7Y1GWSqv tgMCKbO5s2340kG6jPFbMA3zmgJptpX+cjLsKFPtUDhkk4p2B6I9+UD5fM25cRQi 9O8nxvjRZVxXQ67bVKRAr5hfwKuzxFTMp4RnP6STNu3n2LLqCTvdwF/fLVa8dmvM OOQ4kJr4orHuYW1S/SsdMTH7942SrjzbVvasQeIeRH9HyCJqgGVxaARnbmBzbfDr Jni2bOckLSihV1qay6pVMVUwAwEjRzzjjlrPI4uucHuZJCOs42OTv2bG/AoE49u8 9NiCMVTh =oQFB -----END PGP SIGNATURE----- --E0LdhqWfziiBVv4P--