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 A9485C433FE for ; Thu, 13 Jan 2022 13:48:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C6C0181429; Thu, 13 Jan 2022 14:48: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=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="ZMjf8G0h"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2D91683264; Thu, 13 Jan 2022 14:48:19 +0100 (CET) Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) (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 60159800AA for ; Thu, 13 Jan 2022 14:48:16 +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@chromium.org Received: by mail-io1-xd35.google.com with SMTP id w7so3237698ioj.5 for ; Thu, 13 Jan 2022 05:48:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=woNR2x7wlV0KpdI24jh1dxRsxYvmxwCLlwcXNIPGDug=; b=ZMjf8G0hPtOUs8ASjt+lpHH2Wbq/vcsJcKKTcIZ8jQHYN9xOo+od4HVmctUvppWdEV ebEZdCjX0KA8z9qKIUs5j+Q2Jb0NWLPvmuH1V/ODhmxhtJhCq+jSibjAEoXzg/tQ+58s K01rn/oAf9i5Dae8KxKA/5fNkJqLcMzyHaP40= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=woNR2x7wlV0KpdI24jh1dxRsxYvmxwCLlwcXNIPGDug=; b=K+mSSLnf5MlHV5GmmiQJ5qSs6/0t23Ud3pFQzppRLZ/td/bxMpxF0ZSLeGDH1MFiXB 6dztBQVCZP+gi9kB08AyBuesg+URnliPGwVlqmXvRswjtua/qSvGSDmZ3MDNiU+PjRbN f1GLuL/DOe9yMhGuzEVTBEmqgQVg7mTOPuf6abyknRYFcigcV6FFz395y2GkYR7DHy17 PtmSFdPE/KPUuy0oYp9ZtB9D9ly7bX1pOlVnkif8VufJ28XXYW6bNSdpvOvdmgDqVug9 /Yc1DExWdb9jq88HaDK/WOLEpYTWmKzVHCoPCweJ6sojayLRB94B+ibQX4UMERTNMjhB /Tlg== X-Gm-Message-State: AOAM532/T8OMwgum9Hgtox0qLxP5dKQoGTaGN6O5utJ1WM5jwrikya/u VZK20iuahfD9kL1YvlA62HQZJ97fODI5MA== X-Google-Smtp-Source: ABdhPJyB1lv2ifqfbvkTmhNhL9tfWKyOVjdhfI8A3g32XMsT5yyb0a4xW/O1sB1K6AbHUKDVqlQ6sw== X-Received: by 2002:a02:6d15:: with SMTP id m21mr1967469jac.83.1642081694853; Thu, 13 Jan 2022 05:48:14 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r10sm2498886ila.32.2022.01.13.05.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jan 2022 05:48:14 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Rasmus Villemoes , Simon Glass Subject: [PATCH v3 01/12] stddef: Avoid warning with clang with offsetof() Date: Thu, 13 Jan 2022 06:47:55 -0700 Message-Id: <20220113134807.544872-2-sjg@chromium.org> X-Mailer: git-send-email 2.34.1.575.g55b058a8bb-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 --- Changes in v3: - Update commit message to mention this syncs with Linux 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 #endif -- 2.34.1.575.g55b058a8bb-goog