From nobody Fri Dec 13 21:49:52 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Y930K2Td9z5gBNX; Fri, 13 Dec 2024 21:49:53 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y930K06phz4gr7; Fri, 13 Dec 2024 21:49:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734126593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Be0tWhxOLn4u5mjXAbUs8p4s42IOfLhrjx6RJak4ZJY=; b=KYKs5dCcN8OxuHXCdFW3jjx6EAlZteDAC5ZxnOcEg+YXODFoP/UByAVKSj5qYz4rSfy24i FyQGmPWuglEjxito1MdOMpj+7YAWKqrFgEQGi+zz6GD/uVpVZ5YmTACJwvfBZrTDU+Qgz4 s6CzQjX1kyWcSePwoSf2O8EE6ijnQq+O8PRPY2Lf3E0IEM7k3l4zdwGDQHVhkjDuD/cUAq LckclYcXrEOGghV18ZQC57sOHXLMRUJdJhZkJbbtO2K6Ce9EM8XreF8pXa7lvM19Q3zHgV 0c7R5nGsdHBlO0d0jRJkH14ex2OJUsWlKGYtg0IHwgRZyL5AQA4oD9Uy3NzJlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734126593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Be0tWhxOLn4u5mjXAbUs8p4s42IOfLhrjx6RJak4ZJY=; b=i+ifWQNDMFqupgl5jGOYKigvwAGcOB8YxrFqwNi0yx2v8u3lSHNjE9P09nOoYpakkK3Mtg ItTnSeMaPXkte39gjJFn3tttDe4oSyXv6/2mRVJM8jDhcYaVs0KesTxvlZpnmG9teqiPr6 IGmaLkZVsk5E51mIZYfYMr233UIvQmDqGZ/v2BcfuCj8dYY0JmqsICH1PxxPX/wm/fGKb4 udLg1PMrOeFwByTIvrTacQc60tTn0OAglcnbTdlQg16r0fQwNVZeVfwKOlruqMMXsqODbh ki7Xj3SD/HeRmg/JdR4P1TIuJMAlmr2aCjQbG61tpRW50fw8SmQ2Kl9piyw2wQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734126593; a=rsa-sha256; cv=none; b=XfV3hDk/ftL6eRMcCmVz91hLuHOv2Jva1HA9uONNXR/o3JfIV/E4aroaJNA2yGRFOrhxQV TesIiYhUJ/abnr7Kcb+ZuVA3F/Dehebey+VkTU++br3iXQkkaYTkyzboyqF2AsbUlwkDM2 zmHdnRCg0abrVO7sR3wXvDAcyIrJX2jBVl1uHWIhKUs3iZza26Owdl7KBIDL7uN/QEHV7x SLgjXWQ9GBobkC/OEeU0eptVIJfHA4YP6nJxkoFSYngUjK+jY2Bduwg5lXrVDWgUB9HY9z vGoBs4C+qoAcGR72+r+cLczSn8Ei7THy0mA6zPkyfYNMQ5YCZOEN20lR2kAACA== 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 4Y930J6rx2zv4d; Fri, 13 Dec 2024 21:49:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BDLnqmb081167; Fri, 13 Dec 2024 21:49:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BDLnquF081164; Fri, 13 Dec 2024 21:49:52 GMT (envelope-from git) Date: Fri, 13 Dec 2024 21:49:52 GMT Message-Id: <202412132149.4BDLnquF081164@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Brooks Davis Subject: git: c71b427bfa9a - stable/14 - nvi: Replace Clang-only __builtin_is_aligned with C code (#124) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: brooks X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: c71b427bfa9aca65d64cbc95231df5883fc582c9 Auto-Submitted: auto-generated The branch stable/14 has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=c71b427bfa9aca65d64cbc95231df5883fc582c9 commit c71b427bfa9aca65d64cbc95231df5883fc582c9 Author: Zhihao Yuan AuthorDate: 2024-11-27 18:30:46 +0000 Commit: Brooks Davis CommitDate: 2024-12-13 21:05:24 +0000 nvi: Replace Clang-only __builtin_is_aligned with C code (#124) We should use alignof in the future. Obtained from: https://github.com/lichray/nvi2/commit/25c4d7db4ea638a31ac458b733a3b67b0a0ff634 (cherry picked from commit 06a98fefd3d3ff42b7e7832af6c0736b98f167ac) --- contrib/nvi/common/log.c | 2 +- contrib/nvi/common/mem.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/contrib/nvi/common/log.c b/contrib/nvi/common/log.c index d9b142b16d01..d1a1bc6f704a 100644 --- a/contrib/nvi/common/log.c +++ b/contrib/nvi/common/log.c @@ -709,7 +709,7 @@ apply_with(int (*db_func)(SCR *, recno_t, CHAR_T *, size_t), SCR *sp, static size_t blen; static u_char *bp; - if (!__builtin_is_aligned(p, sizeof(unsigned long))) { + if (!is_aligned(p, sizeof(unsigned long))) { if (len > blen) { blen = p2roundup(MAX(len, 512)); REALLOC(sp, bp, u_char *, blen); diff --git a/contrib/nvi/common/mem.h b/contrib/nvi/common/mem.h index d24ec0b50b09..0c83b70dec2f 100644 --- a/contrib/nvi/common/mem.h +++ b/contrib/nvi/common/mem.h @@ -212,6 +212,18 @@ p2roundup(size_t n) return (n); } +/* + * is_aligned -- + * Determine whether the program can safely read an object with an + * alignment requirement from ptr. + * + * See also: https://clang.llvm.org/docs/LanguageExtensions.html#alignment-builtins + */ +static __inline int +is_aligned(void *ptr, size_t alignment) { + return ((uintptr_t)ptr % alignment) == 0; +} + /* Additional TAILQ helper. */ #define TAILQ_ENTRY_ISVALID(elm, field) \ ((elm)->field.tqe_prev != NULL)