From owner-dev-commits-src-branches@freebsd.org Thu Sep 2 21:53:45 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 28A1C6683C9; Thu, 2 Sep 2021 21:53:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H0vnh72NKz4S9v; Thu, 2 Sep 2021 21:53:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C01D520B97; Thu, 2 Sep 2021 21:53:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 182Lriew050745; Thu, 2 Sep 2021 21:53:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 182LriJq050744; Thu, 2 Sep 2021 21:53:44 GMT (envelope-from git) Date: Thu, 2 Sep 2021 21:53:44 GMT Message-Id: <202109022153.182LriJq050744@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: 7dfb8e02e357 - stable/13 - Fix acpica macros that subtract null pointers MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 7dfb8e02e357b2f808bf8eb9e5551f8e237d2dbe Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Sep 2021 21:53:45 -0000 The branch stable/13 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=7dfb8e02e357b2f808bf8eb9e5551f8e237d2dbe commit 7dfb8e02e357b2f808bf8eb9e5551f8e237d2dbe Author: Dimitry Andric AuthorDate: 2021-08-29 11:15:23 +0000 Commit: Dimitry Andric CommitDate: 2021-09-02 21:53:18 +0000 Fix acpica macros that subtract null pointers Clang 13.0.0 produces a new -Werror warning about the ACPI_TO_INTEGER(p) and ACPI_OFFSET(d, f) macros in acpica's actypes.h: sys/contrib/dev/acpica/components/dispatcher/dsopcode.c:708:31: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction] ObjDesc->Region.Address = ACPI_PTR_TO_PHYSADDR (Table); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ sys/contrib/dev/acpica/include/actypes.h:664:41: note: expanded from macro 'ACPI_PTR_TO_PHYSADDR' #define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i) ^~~~~~~~~~~~~~~~~~ sys/contrib/dev/acpica/include/actypes.h:661:41: note: expanded from macro 'ACPI_TO_INTEGER' #define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p, (void *) 0) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sys/contrib/dev/acpica/include/actypes.h:656:82: note: expanded from macro 'ACPI_PTR_DIFF' #define ACPI_PTR_DIFF(a, b) ((ACPI_SIZE) (ACPI_CAST_PTR (UINT8, (a)) - ACPI_CAST_PTR (UINT8, (b)))) ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. This problem of undefined behavior was also reported to acpica by @cem in 2018: https://github.com/acpica/acpica/issues/407, but it seems there was never any fix committed for it upstream. Instead fix these locally, for ACPI_TO_INTEGER by simply casting the incoming pointer to ACPI_SIZE (which corresponds roughly to uintptr_t and size_t), and for ACPI_OFFSET by reusing our __offsetof definition from sys/cdefs.h. Reviewed by: emaste, kib, imp Differential Revision: https://reviews.freebsd.org/D31710 (cherry picked from commit 130a690ae16e1b845629e586203b508eff699f38) --- sys/contrib/dev/acpica/include/actypes.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sys/contrib/dev/acpica/include/actypes.h b/sys/contrib/dev/acpica/include/actypes.h index 48388c2198ed..8fa4818951e8 100644 --- a/sys/contrib/dev/acpica/include/actypes.h +++ b/sys/contrib/dev/acpica/include/actypes.h @@ -658,8 +658,13 @@ typedef UINT64 ACPI_INTEGER; /* Pointer/Integer type conversions */ #define ACPI_TO_POINTER(i) ACPI_CAST_PTR (void, (ACPI_SIZE) (i)) +#ifdef __FreeBSD__ +#define ACPI_TO_INTEGER(p) ((ACPI_SIZE) (p)) +#define ACPI_OFFSET(d, f) ((ACPI_SIZE) __offsetof(d, f)) +#else #define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p, (void *) 0) #define ACPI_OFFSET(d, f) ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) 0) +#endif #define ACPI_PHYSADDR_TO_PTR(i) ACPI_TO_POINTER(i) #define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i)