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 744C4C433EF for ; Thu, 13 Jan 2022 13:50:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EC7EB83042; Thu, 13 Jan 2022 14:50:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org 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=chromium.org header.i=@chromium.org header.b="ZSnO1SRN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A1497832CD; Thu, 13 Jan 2022 14:50:23 +0100 (CET) Received: from mail-vk1-xa32.google.com (mail-vk1-xa32.google.com [IPv6:2607:f8b0:4864:20::a32]) (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 9C15581429 for ; Thu, 13 Jan 2022 14:50:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-vk1-xa32.google.com with SMTP id g5so3890176vkg.0 for ; Thu, 13 Jan 2022 05:50:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9gPwi/i+NsZNiXiDyB/G3HdQLRxhbhM9nI8o4XFq5rE=; b=ZSnO1SRNqBRvnXSQJOnjosgbLPJGKKW7WcWcNFItcMGxRP/sH4plic/7xL0zXsBWqE V/AK5FHnw/BeGviFBjQUpIgKnJgjsK7bSghS3k10mI+iV/qfG6sABBY7ptcimhcPPuTI wMb3Wy+5t2w9Xblt1ShkTFIdyP4W7zcjzn/n0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9gPwi/i+NsZNiXiDyB/G3HdQLRxhbhM9nI8o4XFq5rE=; b=BCZGoPXRgivPF9RLSaOZfZKG59QtpI39Zc44UzaBRO9HxD4XLlLcw0jF/CYG4txCJH JX5akZbUfpDqtKH3Illn4VXSPvlKrcSv7hOr6h/XQQkp8DVA9cat8OynpP10qdIGtfOi Z3SsgEjuGd3RlLdDM8Pg0VNiGnQx0w4LR2ZNzMnKMXOBfLh0wvCgzF6L6rhKC8UudUOK ZqNof9BbMDFeMXGEoL2a8u6F/pM88qmtDX7EsNSME5c5mnTp366Ln3alxg4OCwr3Sty8 heSfR/EtNshA4UCA9INVRB8nDasiQMIaq2LfQUIVnKgD7U8NM0EcbgIwpQAsnTpQn2NO 67BQ== X-Gm-Message-State: AOAM530PqFXWw2zLlXdgCMYEfm2rgHlSaZlmpqeYkvI1e6tG5FcoIPj0 nHmO5MXdEJtz4OET8ioPrarLteK0/hcKq5ehq+5xoA== X-Google-Smtp-Source: ABdhPJzo8gGqBd8GS3ihRWPlkxGHTEp+pudS2S1TFlRqvLtV8uJlhluqqO7q5wvV1Gd+YT363pt6SMX592NWOEys1Yc= X-Received: by 2002:a1f:2d8a:: with SMTP id t132mr2299481vkt.3.1642081819133; Thu, 13 Jan 2022 05:50:19 -0800 (PST) MIME-Version: 1.0 References: <20211101011734.1614781-1-sjg@chromium.org> <20211101011734.1614781-5-sjg@chromium.org> <20220113130734.GJ9207@bill-the-cat> <20220113134152.GL9207@bill-the-cat> In-Reply-To: <20220113134152.GL9207@bill-the-cat> From: Simon Glass Date: Thu, 13 Jan 2022 06:50:08 -0700 Message-ID: Subject: Re: [PATCH 04/31] stddef: Avoid warning with clang with offsetof() To: Tom Rini Cc: Rasmus Villemoes , U-Boot Mailing List , Bin Meng , Ilias Apalodimas , Bill Mills , Heinrich Schuchardt , =?UTF-8?Q?Fran=C3=A7ois_Ozog?= Content-Type: text/plain; charset="UTF-8" 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 Hi Tom, On Thu, 13 Jan 2022 at 06:41, Tom Rini wrote: > > On Thu, Jan 13, 2022 at 06:37:27AM -0700, Simon Glass wrote: > > Hi Tom, Rasmus, > > > > On Thu, 13 Jan 2022 at 06:07, Tom Rini wrote: > > > > > > 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: > > > > > > > > > > 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 > > > > > --- > > > > > > > > > > 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 > > > > > + > > > > > #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 > > > > > > > > > > > > Can we please just drop the useless indirections? Any compiler we care > > > > about provides __builtin_offsetof(), so just make the whole thing > > > > > > > > #undef offsetof > > > > #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) > > > > > > > > And by "compilers we care about", that includes sparse - it has had > > > > __builtin_offsetof ever since 2007. > > > > > > > > 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. > > > > Yes, with this patch, this part of the file is the same as Linux (e.g. v5.16). > > > > So I'd like to apply it as is and deal with improvements later. > > Perhaps in lockstep with Linux? > > Please re-word to be clear this is a functional re-sync with v5.16, > thanks! OK, I sent it and cc'd Rasmus too. I was planning to apply the bloblist stuff this morning, so let me know... Regards, Simon